1 # Copyright 1999-2020 Gentoo Authors
2 # Distributed under the terms of the GNU General Public License v2
5 MY_EXTRAS_VER="20200125-1945Z"
7 CMAKE_MAKEFILE_GENERATOR=emake
9 # Keeping eutils in EAPI=6 for emktemp in pkg_config
11 inherit cmake-utils eutils flag-o-matic linux-info \
12 prefix toolchain-funcs multilib-minimal
14 SRC_URI="https://cdn.mysql.com/Downloads/MySQL-5.7/${PN}-boost-${PV}.tar.gz
15 https://cdn.mysql.com/archives/mysql-5.7/mysql-boost-${PV}.tar.gz
16 http://downloads.mysql.com/archives/MySQL-5.7/${PN}-boost-${PV}.tar.gz"
18 # Gentoo patches to MySQL
19 if [[ "${MY_EXTRAS_VER}" != "live" && "${MY_EXTRAS_VER}" != "none" ]] ; then
21 mirror://gentoo/mysql-extras-${MY_EXTRAS_VER}.tar.bz2
22 https://gitweb.gentoo.org/proj/mysql-extras.git/snapshot/mysql-extras-${MY_EXTRAS_VER}.tar.bz2"
25 HOMEPAGE="https://www.mysql.com/"
26 DESCRIPTION="A fast, multi-threaded, multi-user SQL database server"
29 IUSE="cjk client-libs cracklib debug experimental jemalloc latin1 libressl numa +perl profiling
30 selinux +server static static-libs systemtap tcmalloc test"
32 # Tests always fail when libressl is enabled due to hard-coded ciphers in the tests
33 RESTRICT="!test? ( test ) libressl? ( test )"
35 REQUIRED_USE="?? ( tcmalloc jemalloc )"
37 KEYWORDS="amd64 arm ~arm64 ~hppa ~ia64 ~mips ~ppc ppc64 ~s390 ~sparc x86 ~amd64-linux ~x86-linux ~x64-macos ~x86-macos ~x64-solaris ~x86-solaris"
39 # Shorten the path because the socket path length must be shorter than 107 chars
40 # and we will run a mysql server during test phase
43 if [[ "${MY_EXTRAS_VER}" == "live" ]] ; then
45 EGIT_REPO_URI="https://anongit.gentoo.org/git/proj/mysql-extras.git"
46 EGIT_CHECKOUT_DIR="${WORKDIR}/mysql-extras"
47 EGIT_CLONE_TYPE=shallow
48 MY_PATCH_DIR="${WORKDIR}/mysql-extras"
50 MY_PATCH_DIR="${WORKDIR}/mysql-extras-${MY_EXTRAS_VER}"
54 "${MY_PATCH_DIR}"/20001_all_fix-minimal-build-cmake-mysql-5.7.23.patch
55 "${MY_PATCH_DIR}"/20007_all_cmake-debug-werror-5.7.patch
56 "${MY_PATCH_DIR}"/20009_all_mysql_myodbc_symbol_fix-5.7.10.patch
57 "${MY_PATCH_DIR}"/20018_all_mysql-5.7.29-without-clientlibs-tools.patch
58 "${MY_PATCH_DIR}"/20018_all_mysql-5.7.29-fix-libressl-support.patch
59 "${MY_PATCH_DIR}"/20018_all_mysql-5.7.23-fix-grant_user_lock-a-root.patch
60 "${MY_PATCH_DIR}"/20018_all_mysql-5.7.23-round-off-test-values-for-same-output-on-all-architectures.patch
61 "${MY_PATCH_DIR}"/20018_all_mysql-5.7.25-fix-build-without-server.patch
64 # Be warned, *DEPEND are version-dependant
65 # These are used for both runtime and compiletime
66 # MULTILIB_USEDEP only set for libraries used by the client library
67 COMMON_DEPEND="net-misc/curl:=
69 >=sys-apps/texinfo-4.7-r1
71 client-libs? ( >=sys-libs/zlib-1.2.3:0=[${MULTILIB_USEDEP},static-libs?] )
73 dev-db/mysql-connector-c[${MULTILIB_USEDEP},static-libs?]
74 >=sys-libs/zlib-1.2.3:0=
76 jemalloc? ( dev-libs/jemalloc:0= )
82 >=app-arch/lz4-0_p131:=
83 cjk? ( app-text/mecab:= )
89 numa? ( sys-process/numactl )
91 systemtap? ( >=dev-util/systemtap-1.3:0= )
92 tcmalloc? ( dev-util/google-perftools:0= )
94 !libressl? ( >=dev-libs/openssl-1.0.0:0=[${MULTILIB_USEDEP},static-libs?] )
95 libressl? ( dev-libs/libressl:0=[${MULTILIB_USEDEP},static-libs?] )
98 !libressl? ( >=dev-libs/openssl-1.0.0:0= )
99 libressl? ( dev-libs/libressl:0= )
102 DEPEND="${COMMON_DEPEND}
103 || ( >=sys-devel/gcc-3.4.6 >=sys-devel/gcc-apple-4.0 )
108 experimental? ( net-libs/rpcsvc-proto )
110 static? ( sys-libs/ncurses[static-libs] )
112 acct-group/mysql acct-user/mysql
116 RDEPEND="${COMMON_DEPEND}
117 !dev-db/mariadb !dev-db/mariadb-galera !dev-db/percona-server !dev-db/mysql-cluster
118 client-libs? ( !dev-db/mariadb-connector-c[mysqlcompat] !dev-db/mysql-connector-c dev-libs/protobuf:= )
119 selinux? ( sec-policy/selinux-mysql )
122 acct-group/mysql acct-user/mysql
123 dev-db/mysql-init-scripts
127 # For other stuff to bring us in
128 # dev-perl/DBD-mysql is needed by some scripts installed by MySQL
129 PDEPEND="perl? ( >=dev-perl/DBD-mysql-2.9004 )"
132 MY_SHAREDSTATEDIR=${MY_SHAREDSTATEDIR="${EPREFIX}/usr/share/mysql"}
133 MY_SYSCONFDIR=${MY_SYSCONFDIR="${EPREFIX}/etc/mysql"}
134 MY_LOCALSTATEDIR=${MY_LOCALSTATEDIR="${EPREFIX}/var/lib/mysql"}
135 MY_LOGDIR=${MY_LOGDIR="${EPREFIX}/var/log/mysql"}
137 if [[ -z "${MY_DATADIR}" ]] ; then
139 if [[ -f "${MY_SYSCONFDIR}/my.cnf" ]] ; then
140 MY_DATADIR=`"my_print_defaults" mysqld 2>/dev/null \
141 | sed -ne '/datadir/s|^--datadir=||p' \
143 if [[ -z "${MY_DATADIR}" ]] ; then
144 MY_DATADIR=`grep ^datadir "${MY_SYSCONFDIR}/my.cnf" \
145 | sed -e 's/.*=\s*//' \
149 if [[ -z "${MY_DATADIR}" ]] ; then
150 MY_DATADIR="${MY_LOCALSTATEDIR}"
151 einfo "Using default MY_DATADIR"
153 elog "MySQL MY_DATADIR is ${MY_DATADIR}"
155 if [[ -z "${PREVIOUS_DATADIR}" ]] ; then
156 if [[ -e "${MY_DATADIR}" ]] ; then
157 # If you get this and you're wondering about it, see bug #207636
158 elog "MySQL datadir found in ${MY_DATADIR}"
159 elog "A new one will not be created."
160 PREVIOUS_DATADIR="yes"
162 PREVIOUS_DATADIR="no"
164 export PREVIOUS_DATADIR
167 if [[ ${EBUILD_PHASE} == "config" ]] ; then
169 new_MY_DATADIR=`"my_print_defaults" mysqld 2>/dev/null \
170 | sed -ne '/datadir/s|^--datadir=||p' \
173 if [[ ( -n "${new_MY_DATADIR}" ) && ( "${new_MY_DATADIR}" != "${MY_DATADIR}" ) ]] ; then
174 ewarn "MySQL MY_DATADIR has changed"
175 ewarn "from ${MY_DATADIR}"
176 ewarn "to ${new_MY_DATADIR}"
177 MY_DATADIR="${new_MY_DATADIR}"
182 export MY_SHAREDSTATEDIR MY_SYSCONFDIR
183 export MY_LOCALSTATEDIR MY_LOGDIR
189 local CONFIG_CHECK="~NUMA"
191 local WARNING_NUMA="This package expects NUMA support in kernel which this system does not have at the moment;"
192 WARNING_NUMA+=" Either expect runtime errors, enable NUMA support in kernel or rebuild the package without NUMA support"
199 if [[ ${MERGE_TYPE} != binary ]] ; then
200 local GCC_MAJOR_SET=$(gcc-major-version)
201 local GCC_MINOR_SET=$(gcc-minor-version)
202 # Bug 565584: InnoDB now requires atomic functions introduced with gcc-4.7 on
203 # non x86{,_64} arches
204 if ! use amd64 && ! use x86 && [[ ${GCC_MAJOR_SET} -lt 4 || \
205 ${GCC_MAJOR_SET} -eq 4 && ${GCC_MINOR_SET} -lt 7 ]] ; then
206 eerror "${PN} needs to be built with gcc-4.7 or later."
207 eerror "Please use gcc-config to switch to gcc-4.7 or later version."
212 if has test ${FEATURES} && \
213 use server && ! has userpriv ${FEATURES} ; then
214 eerror "Testing with FEATURES=-userpriv is no longer supported by upstream. Tests MUST be run as non-root."
219 # Here we need to see if the implementation switched client libraries
220 # We check if this is a new instance of the package and a client library already exists
221 local SHOW_ABI_MESSAGE libpath
222 if use client-libs && [[ -z ${REPLACING_VERSIONS} && -e "${EROOT}usr/$(get_libdir)/libmysqlclient.so" ]] ; then
223 libpath=$(readlink "${EROOT}usr/$(get_libdir)/libmysqlclient.so")
224 elog "Due to ABI changes when switching between different client libraries,"
225 elog "revdep-rebuild must find and rebuild all packages linking to libmysqlclient."
226 elog "Please run: revdep-rebuild --library ${libpath}"
227 ewarn "Failure to run revdep-rebuild may cause issues with other programs or libraries"
232 # Make sure the vars are correctly initialized
235 # Create log directory securely if it does not exist
236 [[ -d "${ROOT}${MY_LOGDIR}" ]] || install -d -m0750 -o mysql -g mysql "${ROOT}${MY_LOGDIR}"
239 if [[ -z "${REPLACING_VERSIONS}" ]] ; then
241 elog "You might want to run:"
242 elog "\"emerge --config =${CATEGORY}/${PF}\""
243 elog "if this is a new install."
245 elog "If you are switching server implentations, you should run the"
246 elog "mysql_upgrade tool."
250 elog "If you are upgrading major versions, you should run the"
251 elog "mysql_upgrade tool."
256 # Note about configuration change
258 elog "This version of ${PN} reorganizes the configuration from a single my.cnf"
259 elog "to several files in /etc/mysql/mysql.d."
260 elog "Please backup any changes you made to /etc/mysql/my.cnf"
261 elog "and add them as a new file under /etc/mysql/mysql.d with a .cnf extension."
262 elog "You may have as many files as needed and they are read alphabetically."
263 elog "Be sure the options have the appropriate section headers, i.e. [mysqld]."
270 [[ "${MY_EXTRAS_VER}" == "live" ]] && S="${WORKDIR}/mysql-extras" git-r3_src_unpack
272 mv -f "${WORKDIR}/${P}" "${S}" || die
276 cmake-utils_src_prepare
278 if use jemalloc ; then
279 echo "TARGET_LINK_LIBRARIES(mysqld jemalloc)" >> "${S}/sql/CMakeLists.txt" || die
282 if use tcmalloc ; then
283 echo "TARGET_LINK_LIBRARIES(mysqld tcmalloc)" >> "${S}/sql/CMakeLists.txt" || die
286 # Remove the centos and rhel selinux policies to support mysqld_safe under SELinux
287 if [[ -d "${S}/support-files/SELinux" ]] ; then
288 echo > "${S}/support-files/SELinux/CMakeLists.txt" || die
291 # Remove bundled libs so we cannot accidentally use them
292 # We keep extra/lz4 directory because we use extra/lz4/xxhash.c via sql/CMakeLists.txt:394
294 "${S}"/extra/protobuf \
295 "${S}"/extra/libevent \
299 # Don't clash with dev-db/mysql-connector-c
301 man/my_print_defaults.1 \
303 man/zlib_decompress.1 \
306 if use libressl ; then
307 sed -i 's/OPENSSL_MAJOR_VERSION STREQUAL "1"/OPENSSL_MAJOR_VERSION STREQUAL "2"/' \
308 "${S}/cmake/ssl.cmake" || die
311 sed -i 's~ADD_SUBDIRECTORY(storage/ndb)~~' CMakeLists.txt || die
315 # Bug #114895, bug #110149
316 filter-flags "-O" "-O[01]"
318 append-cxxflags -felide-constructors
320 # bug #283926, with GCC4.4, this is required to get correct behavior.
321 append-flags -fno-strict-aliasing
323 if use client-libs ; then
324 multilib-minimal_src_configure
326 multilib_src_configure
330 multilib_src_configure() {
331 debug-print-function ${FUNCNAME} "$@"
333 if ! multilib_is_native_abi && ! use client-libs ; then
337 CMAKE_BUILD_TYPE="RelWithDebInfo"
339 # debug hack wrt #497532
341 -DCMAKE_C_FLAGS_RELWITHDEBINFO="$(usex debug '' '-DNDEBUG')"
342 -DCMAKE_CXX_FLAGS_RELWITHDEBINFO="$(usex debug '' '-DNDEBUG')"
343 -DMYSQL_DATADIR="${EPREFIX}/var/lib/mysql"
344 -DSYSCONFDIR="${EPREFIX}/etc/mysql"
346 -DINSTALL_DOCDIR=share/doc/${PF}
347 -DINSTALL_DOCREADMEDIR=share/doc/${PF}
348 -DINSTALL_INCLUDEDIR=include/mysql
349 -DINSTALL_INFODIR=share/info
350 -DINSTALL_LIBDIR=$(get_libdir)
351 -DINSTALL_MANDIR=share/man
352 -DINSTALL_MYSQLSHAREDIR=share/mysql
353 -DINSTALL_PLUGINDIR=$(get_libdir)/mysql/plugin
354 -DINSTALL_SCRIPTDIR=share/mysql/scripts
355 -DINSTALL_MYSQLDATADIR="${EPREFIX}/var/lib/mysql"
356 -DINSTALL_SBINDIR=sbin
357 -DINSTALL_SUPPORTFILESDIR="${EPREFIX}/usr/share/mysql"
358 -DCOMPILATION_COMMENT="Gentoo Linux ${PF}"
359 -DWITH_UNIT_TESTS=$(usex test ON OFF)
360 ### TODO: make this system but issues with UTF-8 prevent it
361 -DWITH_EDITLINE=bundled
365 -DENABLED_LOCAL_INFILE=1
366 -DMYSQL_UNIX_ADDR="${EPREFIX}/var/run/mysqld/mysqld.sock"
367 -DWITH_DEFAULT_COMPILER_OPTIONS=0
368 -DWITH_DEFAULT_FEATURE_SET=0
369 # The build forces this to be defined when cross-compiling. We pass it
370 # all the time for simplicity and to make sure it is actually correct.
371 -DSTACK_DIRECTION=$(tc-stack-grows-down && echo -1 || echo 1)
373 -DWITH_BOOST="${S}/boost"
376 mycmakeargs+=( -DINSTALL_MYSQLTESTDIR=share/mysql/mysql-test )
378 mycmakeargs+=( -DINSTALL_MYSQLTESTDIR='' )
381 if ! use client-libs ; then
382 mycmakeargs+=( -DWITHOUT_CLIENTLIBS=YES )
385 # bfd.h is only used starting with 10.1 and can be controlled by NOT_FOR_DISTRIBUTION
386 # systemtap only works on native ABI, bug 530132
387 if multilib_is_native_abi ; then
389 -DENABLE_DTRACE=$(usex systemtap)
399 if multilib_is_native_abi && use server ; then
401 -DWITH_LIBEVENT=system
403 -DWITH_PROTOBUF=system
404 -DWITH_MECAB=$(usex cjk system OFF)
405 -DWITH_NUMA=$(usex numa ON OFF)
406 -DWITH_RAPID=$(usex experimental ON OFF)
409 if [[ ( -n ${MYSQL_DEFAULT_CHARSET} ) && ( -n ${MYSQL_DEFAULT_COLLATION} ) ]] ; then
410 ewarn "You are using a custom charset of ${MYSQL_DEFAULT_CHARSET}"
411 ewarn "and a collation of ${MYSQL_DEFAULT_COLLATION}."
412 ewarn "You MUST file bugs without these variables set."
415 -DDEFAULT_CHARSET=${MYSQL_DEFAULT_CHARSET}
416 -DDEFAULT_COLLATION=${MYSQL_DEFAULT_COLLATION}
418 elif ! use latin1 ; then
420 -DDEFAULT_CHARSET=utf8
421 -DDEFAULT_COLLATION=utf8_general_ci
425 -DDEFAULT_CHARSET=latin1
426 -DDEFAULT_COLLATION=latin1_swedish_ci
432 -DDISABLE_SHARED=$(usex static YES NO)
433 -DWITH_DEBUG=$(usex debug)
434 -DWITH_EMBEDDED_SERVER=OFF
437 if use profiling ; then
438 # Setting to OFF doesn't work: Once set, profiling options will be added
439 # to `mysqld --help` output via sql/sys_vars.cc causing
440 # "main.mysqld--help-notwin" test to fail
441 mycmakeargs+=( -DENABLED_PROFILING=ON )
445 mycmakeargs+=( -DWITH_PIC=1 )
450 -DWITH_EXAMPLE_STORAGE_ENGINE=0
451 -DWITH_ARCHIVE_STORAGE_ENGINE=1
452 -DWITH_BLACKHOLE_STORAGE_ENGINE=1
453 -DWITH_CSV_STORAGE_ENGINE=1
454 -DWITH_FEDERATED_STORAGE_ENGINE=1
455 -DWITH_HEAP_STORAGE_ENGINE=1
456 -DWITH_INNOBASE_STORAGE_ENGINE=1
457 -DWITH_INNODB_MEMCACHED=0
458 -DWITH_MYISAMMRG_STORAGE_ENGINE=1
459 -DWITH_MYISAM_STORAGE_ENGINE=1
460 -DWITH_PARTITION_STORAGE_ENGINE=1
466 -DWITH_EMBEDDED_SERVER=OFF
467 -DEXTRA_CHARSETS=none
471 cmake-utils_src_configure
475 if use client-libs ; then
476 multilib-minimal_src_compile
482 multilib_src_compile() {
483 cmake-utils_src_compile
486 # Official test instructions:
487 # ulimit -n 16500 && \
488 # USE='latin1 perl server' \
489 # FEATURES='test userpriv -usersandbox' \
490 # ebuild mysql-X.X.XX.ebuild \
491 # digest clean package
494 local rawtestname reason
495 rawtestname="${1}" ; shift
497 ewarn "test '${rawtestname}' disabled: '${reason}'"
498 echo ${rawtestname} : ${reason} >> "${T}/disabled.def"
501 local TESTDIR="${BUILD_DIR}/mysql-test"
503 local retstatus_tests
505 if ! use server ; then
506 einfo "Skipping server tests due to minimal build."
510 # Bug #213475 - MySQL _will_ object strenously if your machine is named
511 # localhost. Also causes weird failures.
512 [[ "${HOSTNAME}" == "localhost" ]] && die "Your machine must NOT be named localhost"
514 if [[ $UID -eq 0 ]] ; then
515 die "Testing with FEATURES=-userpriv is no longer supported by upstream. Tests MUST be run as non-root."
517 has usersandbox $FEATURES && ewarn "Some tests may fail with FEATURES=usersandbox"
519 einfo ">>> Test phase [test]: ${CATEGORY}/${PF}"
521 # Run CTest (test-units)
525 # Ensure that parallel runs don't die
526 export MTR_BUILD_THREAD="$((${RANDOM} % 100))"
527 # Enable parallel testing, auto will try to detect number of cores
528 # You may set this by hand.
529 # The default maximum is 8 unless MTR_MAX_PARALLEL is increased
530 export MTR_PARALLEL="${MTR_PARALLEL:-auto}"
532 # create directories because mysqladmin might run out of order
533 mkdir -p "${T}"/var-tests{,/log} || die
536 pushd "${TESTDIR}" &>/dev/null || die
538 touch "${T}/disabled.def"
539 # These are failing in MySQL 5.7 for now and are believed to be
544 for t in auth_sec.keyring_udf ; do
545 _disable_test "$t" "False positives in Gentoo"
549 # - main.xa_prepared_binlog_off: https://bugs.mysql.com/bug.php?id=83340
550 # - rpl.rpl_innodb_info_tbl_slave_tmp_tbl_mismatch: https://bugs.mysql.com/bug.php?id=89223
551 # - rpl.rpl_non_direct_stm_mixing_engines: MDEV-14489
553 main.xa_prepared_binlog_off \
554 rpl.rpl_innodb_info_tbl_slave_tmp_tbl_mismatch \
555 rpl.rpl_non_direct_stm_mixing_engines \
557 _disable_test "$t" "Unstable test"
561 gis.geometry_class_attri_prop \
562 gis.geometry_property_function_issimple \
563 gis.gis_bugs_crashes \
564 gis.spatial_op_testingfunc_mix \
565 gis.spatial_analysis_functions_buffer \
566 gis.spatial_analysis_functions_distance \
567 gis.spatial_utility_function_distance_sphere \
568 gis.spatial_utility_function_simplify \
569 gis.spatial_analysis_functions_centroid \
571 _disable_test "$t" "Known rounding error with latest AMD processors"
574 if use numa && use kernel_linux ; then
576 if ! linux_config_exists || ! linux_chkconfig_present NUMA ; then
577 for t in sys_vars.innodb_numa_interleave_basic ; do
578 _disable_test "$t" "Test $t requires system with NUMA support"
583 if ! use latin1 ; then
584 # The following tests will fail if DEFAULT_CHARSET
585 # isn't set to latin1:
587 binlog.binlog_mysqlbinlog_filter \
588 binlog.binlog_xa_prepared_disconnect \
589 funcs_1.is_columns_mysql \
590 funcs_1.is_tables_mysql \
591 funcs_1.is_triggers \
592 innodb.innodb_pagesize_max_recordsize \
593 innodb.innodb-system-table-view \
594 innodb.mysqldump_max_recordsize \
595 main.mysql_client_test \
596 main.mysqld--help-notwin \
598 main.information_schema \
599 perfschema.binlog_edge_mix \
600 perfschema.binlog_edge_stmt \
601 rpl.rpl_xa_survive_disconnect \
602 rpl.rpl_xa_survive_disconnect_lsu_off \
603 rpl.rpl_xa_survive_disconnect_table \
605 _disable_test "$t" "Requires DEFAULT_CHARSET=latin1 but USE=-latin1 is set"
609 if has_version '>=dev-libs/openssl-1.1.1' ; then
610 # Tests are expecting <openssl-1.1.1 default cipher
612 auth_sec.cert_verify \
613 auth_sec.mysql_ssl_connection \
614 auth_sec.openssl_cert_generation \
615 auth_sec.ssl_auto_detect \
618 binlog.binlog_grant_alter_user \
619 encryption.innodb_onlinealter_encryption \
620 main.grant_alter_user_qa \
621 main.grant_user_lock_qa \
622 main.mysql_ssl_default \
624 main.plugin_auth_sha256_tls \
633 main.ssl_verify_identity \
634 x.connection_tls_version \
635 x.connection_openssl \
637 _disable_test "$t" "Requires <dev-libs/openssl-1.1.1"
641 # Try to increase file limits to increase test coverage
642 if ! ulimit -n 16500 1>/dev/null 2>&1 ; then
643 # Upper limit comes from parts.partition_* tests
644 ewarn "For maximum test coverage please raise open file limit to 16500 (ulimit -n 16500) before calling the package manager."
646 if ! ulimit -n 4162 1>/dev/null 2>&1 ; then
647 # Medium limit comes from '[Warning] Buffered warning: Could not increase number of max_open_files to more than 3000 (request: 4162)'
648 ewarn "For medium test coverage please raise open file limit to 4162 (ulimit -n 4162) before calling the package manager."
650 if ! ulimit -n 3000 1>/dev/null 2>&1 ; then
651 ewarn "For minimum test coverage please raise open file limit to 3000 (ulimit -n 3000) before calling the package manager."
653 einfo "Will run test suite with open file limit set to 3000 (minimum test coverage)."
656 einfo "Will run test suite with open file limit set to 4162 (medium test coverage)."
659 einfo "Will run test suite with open file limit set to 16500 (best test coverage)."
662 # run mysql-test tests
663 perl mysql-test-run.pl --force --vardir="${T}/var-tests" --reorder --skip-test=tokudb --skip-test-list="${T}/disabled.def"
666 popd &>/dev/null || die
668 # Cleanup is important for these testcases.
669 pkill -9 -f "${S}/ndb" 2>/dev/null
670 pkill -9 -f "${S}/sql" 2>/dev/null
673 [[ $retstatus_unit -eq 0 ]] || failures="${failures} test-unit"
674 [[ $retstatus_tests -eq 0 ]] || failures="${failures} tests"
676 [[ -z "$failures" ]] || die "Test failures: $failures"
677 einfo "Tests successfully completed"
681 local MULTILIB_WRAPPED_HEADERS
682 local MULTILIB_CHOST_TOOLS
683 if use client-libs ; then
684 # headers with ABI specific data
685 MULTILIB_WRAPPED_HEADERS=(
686 /usr/include/mysql/server/my_config.h
687 /usr/include/mysql/server/mysql_version.h )
689 # wrap the config scripts
690 MULTILIB_CHOST_TOOLS=( /usr/bin/mysql_config )
691 multilib-minimal_src_install
694 multilib_src_install_all
698 # Intentionally override eclass function
699 multilib_src_install() {
701 cmake-utils_src_install
703 # Kill old libmysqclient_r symlinks if they exist. Time to fix what depends on them.
704 find "${D}" -name 'libmysqlclient_r.*' -type l -delete || die
707 multilib_src_install_all() {
708 # Make sure the vars are correctly initialized
712 einfo "Making Convenience links for mysqlcheck multi-call binary"
713 dosym "mysqlcheck" "/usr/bin/mysqlanalyze"
714 dosym "mysqlcheck" "/usr/bin/mysqlrepair"
715 dosym "mysqlcheck" "/usr/bin/mysqloptimize"
717 # INSTALL_LAYOUT=STANDALONE causes cmake to create a /usr/data dir
718 if [[ -d "${ED}/usr/data" ]] ; then
719 rm -Rf "${ED}/usr/data" || die
722 # Unless they explicitly specific USE=test, then do not install the
723 # testsuite. It DOES have a use to be installed, esp. when you want to do a
724 # validation of your database configuration after tuning it.
726 rm -rf "${D}/${MY_SHAREDSTATEDIR}/mysql-test"
729 # Configuration stuff
730 einfo "Building default configuration ..."
731 insinto "${MY_SYSCONFDIR#${EPREFIX}}"
732 [[ -f "${S}/scripts/mysqlaccess.conf" ]] && doins "${S}"/scripts/mysqlaccess.conf
733 cp "${FILESDIR}/my.cnf-5.7" "${TMPDIR}/my.cnf" || die
734 eprefixify "${TMPDIR}/my.cnf"
735 doins "${TMPDIR}/my.cnf"
736 insinto "${MY_SYSCONFDIR#${EPREFIX}}/mysql.d"
737 cp "${FILESDIR}/my.cnf.distro-client" "${TMPDIR}/50-distro-client.cnf" || die
738 eprefixify "${TMPDIR}/50-distro-client.cnf"
739 doins "${TMPDIR}/50-distro-client.cnf"
742 mycnf_src="my.cnf.distro-server"
743 sed -e "s!@DATADIR@!${MY_DATADIR}!g" \
744 "${FILESDIR}/${mycnf_src}" \
745 > "${TMPDIR}/my.cnf.ok" || die
748 sed -i -r -e '/^user[[:space:]]*=[[:space:]]*mysql$/d' \
749 "${TMPDIR}/my.cnf.ok" || die
754 -e "/character-set/s|utf8|latin1|g" \
755 "${TMPDIR}/my.cnf.ok" || die
758 eprefixify "${TMPDIR}/my.cnf.ok"
760 newins "${TMPDIR}/my.cnf.ok" 50-distro-server.cnf
763 #Remove mytop if perl is not selected
764 [[ -e "${ED}/usr/bin/mytop" ]] && ! use perl && rm -f "${ED}/usr/bin/mytop"
769 local mypd="${EROOT%/}"/usr/bin/my_print_defaults
772 local extra_options="${3}"
773 "${mypd}" $extra_options $section | sed -n "/^${flag}/s,${flag},,gp"
775 local old_MY_DATADIR="${MY_DATADIR}"
776 local old_HOME="${HOME}"
777 # my_print_defaults needs to read stuff in $HOME/.my.cnf
778 export HOME=${EPREFIX}/root
780 # Make sure the vars are correctly initialized
783 [[ -z "${MY_DATADIR}" ]] && die "Sorry, unable to find MY_DATADIR"
784 if [[ ! -x "${EROOT%/}/usr/sbin/mysqld" ]] ; then
785 die "Minimal builds do NOT include the MySQL server"
788 if [[ ( -n "${MY_DATADIR}" ) && ( "${MY_DATADIR}" != "${old_MY_DATADIR}" ) ]] ; then
789 local MY_DATADIR_s="${ROOT%/}/${MY_DATADIR}"
790 MY_DATADIR_s="${MY_DATADIR_s%%/}"
791 local old_MY_DATADIR_s="${ROOT%/}/${old_MY_DATADIR}"
792 old_MY_DATADIR_s="${old_MY_DATADIR_s%%/}"
794 if [[ ( -d "${old_MY_DATADIR_s}" ) && ( "${old_MY_DATADIR_s}" != / ) ]] ; then
795 if [[ -d "${MY_DATADIR_s}" ]] ; then
796 ewarn "Both ${old_MY_DATADIR_s} and ${MY_DATADIR_s} exist"
797 ewarn "Attempting to use ${MY_DATADIR_s} and preserving ${old_MY_DATADIR_s}"
799 elog "Moving MY_DATADIR from ${old_MY_DATADIR_s} to ${MY_DATADIR_s}"
800 mv --strip-trailing-slashes -T "${old_MY_DATADIR_s}" "${MY_DATADIR_s}" \
801 || die "Moving MY_DATADIR failed"
804 ewarn "Previous MY_DATADIR (${old_MY_DATADIR_s}) does not exist"
805 if [[ -d "${MY_DATADIR_s}" ]] ; then
806 ewarn "Attempting to use ${MY_DATADIR_s}"
808 eerror "New MY_DATADIR (${MY_DATADIR_s}) does not exist"
809 die "Configuration Failed! Please reinstall ${CATEGORY}/${PN}"
818 if [[ -z "${MYSQL_ROOT_PASSWORD}" ]] ; then
819 local tmp_mysqld_password_source=
821 for tmp_mysqld_password_source in mysql client ; do
822 einfo "Trying to get password for mysql 'root' user from '${tmp_mysqld_password_source}' section ..."
823 MYSQL_ROOT_PASSWORD="$(_getoptval "${tmp_mysqld_password_source}" password)"
824 if [[ -n "${MYSQL_ROOT_PASSWORD}" ]] ; then
825 if [[ ${MYSQL_ROOT_PASSWORD} == *$'\n'* ]] ; then
826 ewarn "Ignoring password from '${tmp_mysqld_password_source}' section due to newline character (do you have multiple password options set?)!"
831 einfo "Found password in '${tmp_mysqld_password_source}' section!"
836 # Sometimes --show is required to display passwords in some implementations of my_print_defaults
837 if [[ "${MYSQL_ROOT_PASSWORD}" == '*****' ]] ; then
838 MYSQL_ROOT_PASSWORD="$(_getoptval "${tmp_mysqld_password_source}" password --show)"
841 unset tmp_mysqld_password_source
843 MYSQL_TMPDIR="$(_getoptval mysqld tmpdir)"
844 # These are dir+prefix
845 MYSQL_RELAY_LOG="$(_getoptval mysqld relay-log)"
846 MYSQL_RELAY_LOG=${MYSQL_RELAY_LOG%/*}
847 MYSQL_LOG_BIN="$(_getoptval mysqld log-bin)"
848 MYSQL_LOG_BIN=${MYSQL_LOG_BIN%/*}
850 if [[ ! -d "${EROOT%/}/$MYSQL_TMPDIR" ]] ; then
851 einfo "Creating MySQL tmpdir $MYSQL_TMPDIR"
852 install -d -m 770 -o mysql -g mysql "${EROOT%/}/$MYSQL_TMPDIR"
855 if [[ ! -d "${EROOT%/}/$MYSQL_LOG_BIN" ]] ; then
856 einfo "Creating MySQL log-bin directory $MYSQL_LOG_BIN"
857 install -d -m 770 -o mysql -g mysql "${EROOT%/}/$MYSQL_LOG_BIN"
860 if [[ ! -d "${EROOT%/}/$MYSQL_RELAY_LOG" ]] ; then
861 einfo "Creating MySQL relay-log directory $MYSQL_RELAY_LOG"
862 install -d -m 770 -o mysql -g mysql "${EROOT%/}/$MYSQL_RELAY_LOG"
865 if [[ -d "${ROOT%/}/${MY_DATADIR}/mysql" ]] ; then
866 ewarn "You have already a MySQL database in place."
867 ewarn "(${ROOT%/}/${MY_DATADIR}/*)"
868 ewarn "Please rename or delete it if you wish to replace it."
869 die "MySQL database already exists!"
872 # Bug #213475 - MySQL _will_ object strenously if your machine is named
873 # localhost. Also causes weird failures.
874 [[ "${HOSTNAME}" == "localhost" ]] && die "Your machine must NOT be named localhost"
876 if [[ -z "${MYSQL_ROOT_PASSWORD}" ]] ; then
878 einfo "Please provide a password for the mysql 'root' user now"
879 einfo "or through the ${HOME}/.my.cnf file."
880 ewarn "Avoid [\"'\\_%] characters in the password"
881 read -rsp " >" pwd1 ; echo
883 einfo "Retype the password"
884 read -rsp " >" pwd2 ; echo
886 if [[ "x$pwd1" != "x$pwd2" ]] ; then
887 die "Passwords are not the same"
889 MYSQL_ROOT_PASSWORD="${pwd1}"
894 local sqltmp="$(emktemp)"
896 # Fix bug 446200. Don't reference host my.cnf, needs to come first,
897 # see http://bugs.mysql.com/bug.php?id=31312
898 use prefix && options="${options} '--defaults-file=${MY_SYSCONFDIR}/my.cnf'"
900 # Figure out which options we need to disable to do the setup
901 local helpfile="${TMPDIR%/}/mysqld-help"
902 "${EROOT%/}/usr/sbin/mysqld" --verbose --help >"${helpfile}" 2>/dev/null
903 for opt in host-cache name-resolve networking slave-start \
904 federated ssl log-bin relay-log slow-query-log external-locking \
907 optexp="--(skip-)?${opt}" optfull="--loose-skip-${opt}"
908 egrep -sq -- "${optexp}" "${helpfile}" && options="${options} ${optfull}"
911 einfo "Creating the mysql database and setting proper permissions on it ..."
913 # Now that /var/run is a tmpfs mount point, we need to ensure it exists before using it
914 PID_DIR="${EROOT%/}/var/run/mysqld"
915 if [[ ! -d "${PID_DIR}" ]] ; then
916 install -d -m 755 -o mysql -g mysql "${PID_DIR}" || die "Could not create pid directory"
919 if [[ ! -d "${MY_DATADIR}" ]] ; then
920 install -d -m 750 -o mysql -g mysql "${MY_DATADIR}" || die "Could not create data directory"
923 pushd "${TMPDIR}" &>/dev/null || die
925 # Filling timezones, see
926 # http://dev.mysql.com/doc/mysql/en/time-zone-support.html
927 echo "USE mysql;" >"${sqltmp}"
928 "${EROOT%/}/usr/bin/mysql_tzinfo_to_sql" "${EROOT%/}/usr/share/zoneinfo" >> "${sqltmp}" 2>/dev/null
929 chown mysql "${sqltmp}" || die
931 # --initialize-insecure will not set root password
932 # --initialize would set a random one in the log which we don't need as we set it ourselves
933 local cmd=( "${EROOT%/}/usr/sbin/mysqld" "--initialize-insecure" "--init-file='${sqltmp}'" )
934 cmd+=( "--basedir=${EPREFIX}/usr" ${options} "--datadir=${ROOT%/}${MY_DATADIR}" "--tmpdir=${ROOT%/}${MYSQL_TMPDIR}" )
935 einfo "Command: ${cmd[*]}"
936 su -s /bin/sh -c "${cmd[*]}" mysql \
937 >"${TMPDIR%/}"/mysql_install_db.log 2>&1
938 if [[ $? -ne 0 ]] ; then
939 grep -B5 -A999 -i "ERROR" "${TMPDIR%/}"/mysql_install_db.log 1>&2
940 die "Failed to initialize mysqld. Please review ${EPREFIX}/var/log/mysql/mysqld.err AND ${TMPDIR%/}/mysql_install_db.log"
942 popd &>/dev/null || die
943 [[ -f "${ROOT%/}/${MY_DATADIR}/mysql/user.frm" ]] \
944 || die "MySQL databases not installed"
946 use prefix || options="${options} --user=mysql"
948 local socket="${EROOT%/}/var/run/mysqld/mysqld${RANDOM}.sock"
949 local pidfile="${EROOT%/}/var/run/mysqld/mysqld${RANDOM}.pid"
950 local mysqld="${EROOT%/}/usr/sbin/mysqld \
952 $(use prefix || echo --user=mysql) \
954 --basedir=${EROOT%/}/usr \
955 --datadir=${ROOT%/}/${MY_DATADIR} \
956 --max_allowed_packet=8M \
957 --net_buffer_length=16K \
959 --pid-file=${pidfile} \
960 --tmpdir=${ROOT}/${MYSQL_TMPDIR}"
961 #einfo "About to start mysqld: ${mysqld}"
962 ebegin "Starting mysqld"
963 einfo "Command ${mysqld}"
966 while ! [[ -S "${socket}" || "${maxtry}" -lt 1 ]] ; do
967 maxtry=$((${maxtry}-1))
973 if ! [[ -S "${socket}" ]] ; then
974 die "Completely failed to start up mysqld with: ${mysqld}"
977 ebegin "Setting root password"
978 # Do this from memory, as we don't want clear text passwords in temp files
979 local sql="ALTER USER 'root'@'localhost' IDENTIFIED WITH mysql_native_password BY '${MYSQL_ROOT_PASSWORD}'"
980 "${EROOT%/}/usr/bin/mysql" \
982 "--socket=${socket}" \
987 # Stop the server and cleanup
988 einfo "Stopping the server ..."
989 kill $(< "${pidfile}" )