1 # Copyright 1999-2020 Gentoo Authors
2 # Distributed under the terms of the GNU General Public License v2
5 MY_EXTRAS_VER="20190822-1908Z"
7 CMAKE_MAKEFILE_GENERATOR=emake
9 # Keeping eutils in EAPI=6 for emktemp in pkg_config
11 inherit eutils flag-o-matic prefix toolchain-funcs \
12 cmake-utils multilib-build
14 SRC_URI="http://cdn.mysql.com/Downloads/MySQL-5.6/${P}.tar.gz
15 https://cdn.mysql.com/archives/mysql-5.6/${P}.tar.gz
16 http://downloads.mysql.com/archives/MySQL-5.6/${P}.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
23 https://dev.gentoo.org/~grknight/distfiles/mysql-extras-${MY_EXTRAS_VER}.tar.bz2
24 https://dev.gentoo.org/~robbat2/distfiles/mysql-extras-${MY_EXTRAS_VER}.tar.bz2
25 https://dev.gentoo.org/~jmbsvicetto/distfiles/mysql-extras-${MY_EXTRAS_VER}.tar.bz2"
28 HOMEPAGE="https://www.mysql.com/"
29 DESCRIPTION="A fast, multi-threaded, multi-user SQL database server"
32 IUSE="client-libs cracklib debug jemalloc latin1 libressl numa +perl profiling selinux
33 +server static static-libs systemtap tcmalloc test yassl"
35 # Tests always fail when libressl is enabled due to hard-coded ciphers in the tests
36 RESTRICT="!test? ( test ) libressl? ( test )"
38 REQUIRED_USE="?? ( tcmalloc jemalloc ) static? ( yassl )"
40 KEYWORDS="amd64 arm ~hppa ~ia64 ~mips ppc ppc64 ~s390 ~sparc x86 ~amd64-linux ~x86-linux ~x64-macos ~x86-macos ~x64-solaris ~x86-solaris"
42 # Shorten the path because the socket path length must be shorter than 107 chars
43 # and we will run a mysql server during test phase
46 if [[ "${MY_EXTRAS_VER}" == "live" ]] ; then
48 EGIT_REPO_URI="https://anongit.gentoo.org/git/proj/mysql-extras.git"
49 EGIT_CHECKOUT_DIR="${WORKDIR}/mysql-extras"
50 EGIT_CLONE_TYPE=shallow
51 MY_PATCH_DIR="${WORKDIR}/mysql-extras"
53 MY_PATCH_DIR="${WORKDIR}/mysql-extras-${MY_EXTRAS_VER}"
57 "${MY_PATCH_DIR}"/01050_all_mysql_config_cleanup-5.6.patch
58 "${MY_PATCH_DIR}"/02040_all_embedded-library-shared-5.5.10.patch
59 "${MY_PATCH_DIR}"/20006_all_cmake_elib-mysql-5.6.35.patch
60 "${MY_PATCH_DIR}"/20007_all_cmake-debug-werror-5.6.22.patch
61 "${MY_PATCH_DIR}"/20008_all_mysql-tzinfo-symlink-5.6.37.patch
62 "${MY_PATCH_DIR}"/20009_all_mysql_myodbc_symbol_fix-5.6.patch
63 "${MY_PATCH_DIR}"/20018_all_mysql-5.6.25-without-clientlibs-tools.patch
64 "${MY_PATCH_DIR}"/20027_all_mysql-5.5-perl5.26-includes.patch
65 "${MY_PATCH_DIR}"/20031_all_mysql-5.6-fix-monitor.test.patch
66 "${MY_PATCH_DIR}"/20036_all_mysql-5.6-fix-rpl_semi_sync_shutdown_hang.test.patch
67 "${MY_PATCH_DIR}"/20018_all_mysql-5.6.44-fix-libressl-support.patch
68 "${MY_PATCH_DIR}"/20018_all_mysql-5.6.44-add-openssl-1.1-support.patch
71 # Be warned, *DEPEND are version-dependant
72 # These are used for both runtime and compiletime
80 >=sys-apps/texinfo-4.7-r1
81 jemalloc? ( dev-libs/jemalloc:0= )
82 tcmalloc? ( dev-util/google-perftools:0= )
83 systemtap? ( >=dev-util/systemtap-1.3:0= )
85 !libressl? ( >=dev-libs/openssl-1.0.0:0= )
86 libressl? ( =dev-libs/libressl-2.6.5*:0= )
88 >=sys-libs/zlib-1.2.3:0=
91 numa? ( sys-process/numactl )
93 !client-libs? ( dev-db/mysql-connector-c[${MULTILIB_USEDEP},static-libs?] )
96 static? ( sys-libs/ncurses[static-libs] )
98 acct-group/mysql acct-user/mysql
101 || ( >=sys-devel/gcc-3.4.6 >=sys-devel/gcc-apple-4.0 )
103 RDEPEND="selinux? ( sec-policy/selinux-mysql )
104 client-libs? ( !dev-db/mariadb-connector-c[mysqlcompat] !dev-db/mysql-connector-c )
105 !dev-db/mariadb !dev-db/mariadb-galera !dev-db/percona-server !dev-db/mysql-cluster
108 acct-group/mysql acct-user/mysql
109 dev-db/mysql-init-scripts
114 # For other stuff to bring us in
115 # dev-perl/DBD-mysql is needed by some scripts installed by MySQL
116 PDEPEND="perl? ( >=dev-perl/DBD-mysql-2.9004 )"
119 if [[ ${MERGE_TYPE} != binary ]] ; then
120 local GCC_MAJOR_SET=$(gcc-major-version)
121 local GCC_MINOR_SET=$(gcc-minor-version)
122 # Bug 565584. InnoDB now requires atomic functions introduced with gcc-4.7 on
123 # non x86{,_64} arches
124 if ! use amd64 && ! use x86 && [[ ${GCC_MAJOR_SET} -lt 4 || \
125 ${GCC_MAJOR_SET} -eq 4 && ${GCC_MINOR_SET} -lt 7 ]] ; then
126 eerror "${PN} needs to be built with gcc-4.7 or later."
127 eerror "Please use gcc-config to switch to gcc-4.7 or later version."
131 if has test ${FEATURES} && \
132 use server && ! has userpriv ${FEATURES} ; then
133 eerror "Testing with FEATURES=-userpriv is no longer supported by upstream. Tests MUST be run as non-root."
138 # Here we need to see if the implementation switched client libraries
139 # We check if this is a new instance of the package and a client library already exists
140 local SHOW_ABI_MESSAGE libpath
141 if use client-libs && [[ -z ${REPLACING_VERSIONS} && -e "${EROOT%/}/usr/$(get_libdir)/libmysqlclient.so" ]] ; then
142 libpath=$(readlink "${EROOT%/}/usr/$(get_libdir)/libmysqlclient.so")
143 elog "Due to ABI changes when switching between different client libraries,"
144 elog "revdep-rebuild must find and rebuild all packages linking to libmysqlclient."
145 elog "Please run: revdep-rebuild --library ${libpath}"
146 ewarn "Failure to run revdep-rebuild may cause issues with other programs or libraries"
151 # Make sure the vars are correctly initialized
154 # Create log directory securely if it does not exist
155 [[ -d "${ROOT}${MY_LOGDIR}" ]] || install -d -m0750 -o mysql -g mysql "${ROOT}${MY_LOGDIR}"
158 if [[ -z "${REPLACING_VERSIONS}" ]] ; then
160 elog "You might want to run:"
161 elog "\"emerge --config =${CATEGORY}/${PF}\""
162 elog "if this is a new install."
164 elog "If you are switching server implentations, you should run the"
165 elog "mysql_upgrade tool."
169 elog "If you are upgrading major versions, you should run the"
170 elog "mysql_upgrade tool."
179 [[ "${MY_EXTRAS_VER}" == "live" ]] && S="${WORKDIR}/mysql-extras" git-r3_src_unpack
181 mv -f "${WORKDIR}/${P}" "${S}" || die
186 echo > "${S%/}/storage/${1}/CMakeLists.txt" || die
190 echo > "${S%/}/plugin/${1}/CMakeLists.txt" || die
193 if use jemalloc ; then
194 echo "TARGET_LINK_LIBRARIES(mysqld jemalloc)" >> "${S}/sql/CMakeLists.txt" || die
196 if use tcmalloc; then
197 echo "TARGET_LINK_LIBRARIES(mysqld tcmalloc)" >> "${S}/sql/CMakeLists.txt" || die
199 # Remove the centos and rhel selinux policies to support mysqld_safe under SELinux
200 if [[ -d "${S}/support-files/SELinux" ]] ; then
201 echo > "${S}/support-files/SELinux/CMakeLists.txt" || die
204 # Don't clash with dev-db/mysql-connector-c
206 man/my_print_defaults.1 \
210 if use libressl ; then
211 sed -i 's/OPENSSL_MAJOR_VERSION STREQUAL "1"/OPENSSL_MAJOR_VERSION STREQUAL "2"/' \
212 "${S}/cmake/ssl.cmake" || die
215 sed -i 's~ADD_SUBDIRECTORY(storage/ndb)~~' CMakeLists.txt || die
218 local server_plugins=( semisync )
219 local test_plugins=( audit_null daemon_example fulltext )
220 if ! use server; then # These plugins are for the server
221 for plugin in "${server_plugins[@]}" ; do
222 _disable_plugin "${plugin}"
226 if ! use test; then # These plugins are only used during testing
227 for plugin in "${test_plugins[@]}" ; do
228 _disable_plugin "${plugin}"
232 # Don't build example
233 _disable_engine example
235 _disable_plugin innodb_memcached
237 cmake-utils_src_prepare
241 # bug 508724 mariadb cannot use ld.gold
243 # Bug #114895, bug #110149
244 filter-flags "-O" "-O[01]"
246 append-cxxflags -felide-constructors
248 # bug #283926, with GCC4.4, this is required to get correct behavior.
249 append-flags -fno-strict-aliasing
251 CMAKE_BUILD_TYPE="RelWithDebInfo"
253 # debug hack wrt #497532
255 -DCMAKE_C_FLAGS_RELWITHDEBINFO="$(usex debug '' '-DNDEBUG')"
256 -DCMAKE_CXX_FLAGS_RELWITHDEBINFO="$(usex debug '' '-DNDEBUG')"
257 -DMYSQL_DATADIR="${EPREFIX}/var/lib/mysql"
258 -DSYSCONFDIR="${EPREFIX}/etc/mysql"
260 -DINSTALL_DOCDIR=share/doc/${PF}
261 -DINSTALL_DOCREADMEDIR=share/doc/${PF}
262 -DINSTALL_INCLUDEDIR=include/mysql
263 -DINSTALL_INFODIR=share/info
264 -DINSTALL_LIBDIR=$(get_libdir)
265 -DINSTALL_MANDIR=share/man
266 -DINSTALL_MYSQLSHAREDIR=share/mysql
267 -DINSTALL_PLUGINDIR=$(get_libdir)/mysql/plugin
268 -DINSTALL_SCRIPTDIR=share/mysql/scripts
269 -DINSTALL_MYSQLDATADIR="${EPREFIX}/var/lib/mysql"
270 -DINSTALL_SBINDIR=sbin
271 -DINSTALL_SUPPORTFILESDIR="${EPREFIX}/usr/share/mysql"
272 -DCOMPILATION_COMMENT="Gentoo Linux ${PF}"
273 -DWITH_UNIT_TESTS=$(usex test ON OFF)
274 ### TODO: make this system but issues with UTF-8 prevent it
275 -DWITH_EDITLINE=bundled
278 -DENABLED_LOCAL_INFILE=1
279 -DMYSQL_UNIX_ADDR="${EPREFIX}/var/run/mysqld/mysqld.sock"
280 -DWITH_DEFAULT_COMPILER_OPTIONS=0
281 -DWITH_DEFAULT_FEATURE_SET=0
282 # The build forces this to be defined when cross-compiling. We pass it
283 # all the time for simplicity and to make sure it is actually correct.
284 -DSTACK_DIRECTION=$(tc-stack-grows-down && echo -1 || echo 1)
286 -DWITHOUT_CLIENTLIBS=YES
287 -DENABLE_DTRACE=$(usex systemtap)
288 -DWITH_SSL=$(usex yassl bundled system)
289 -DINSTALL_MYSQLTESTDIR=$(usex test 'share/mysql/mysql-test' '')
290 -DWITHOUT_VALIDATE_PASSWORD=1
295 if [[ ( -n ${MYSQL_DEFAULT_CHARSET} ) && ( -n ${MYSQL_DEFAULT_COLLATION} ) ]]; then
296 ewarn "You are using a custom charset of ${MYSQL_DEFAULT_CHARSET}"
297 ewarn "and a collation of ${MYSQL_DEFAULT_COLLATION}."
298 ewarn "You MUST file bugs without these variables set."
301 -DDEFAULT_CHARSET=${MYSQL_DEFAULT_CHARSET}
302 -DDEFAULT_COLLATION=${MYSQL_DEFAULT_COLLATION}
305 elif ! use latin1 ; then
307 -DDEFAULT_CHARSET=utf8
308 -DDEFAULT_COLLATION=utf8_general_ci
312 -DDEFAULT_CHARSET=latin1
313 -DDEFAULT_COLLATION=latin1_swedish_ci
317 -DWITH_NUMA=$(usex numa ON OFF)
319 -DDISABLE_SHARED=$(usex static YES NO)
320 -DWITH_DEBUG=$(usex debug)
321 -DWITH_EMBEDDED_SERVER=OFF
324 if use profiling ; then
325 # Setting to OFF doesn't work: Once set, profiling options will be added
326 # to `mysqld --help` output via sql/sys_vars.cc causing
327 # "main.mysqld--help-notwin" test to fail
328 mycmakeargs+=( -DENABLED_PROFILING=ON )
332 mycmakeargs+=( -DWITH_PIC=1 )
337 -DWITH_ARCHIVE_STORAGE_ENGINE=1
338 -DWITH_BLACKHOLE_STORAGE_ENGINE=1
339 -DWITH_CSV_STORAGE_ENGINE=1
340 -DWITH_HEAP_STORAGE_ENGINE=1
341 -DWITH_INNOBASE_STORAGE_ENGINE=1
342 -DWITH_MYISAMMRG_STORAGE_ENGINE=1
343 -DWITH_MYISAM_STORAGE_ENGINE=1
344 -DWITH_PARTITION_STORAGE_ENGINE=1
345 -DWITH_INNODB_MEMCACHED=0
351 -DWITH_EMBEDDED_SERVER=OFF
352 -DEXTRA_CHARSETS=none
356 cmake-utils_src_configure
360 cmake-utils_src_compile
364 cmake-utils_src_install
366 # Kill old libmysqclient_r symlinks if they exist. Time to fix what depends on them.
367 find "${D}" -name 'libmysqlclient_r.*' -type l -delete || die
368 # Make sure the vars are correctly initialized
372 einfo "Making Convenience links for mysqlcheck multi-call binary"
373 dosym "mysqlcheck" "/usr/bin/mysqlanalyze"
374 dosym "mysqlcheck" "/usr/bin/mysqlrepair"
375 dosym "mysqlcheck" "/usr/bin/mysqloptimize"
377 # INSTALL_LAYOUT=STANDALONE causes cmake to create a /usr/data dir
378 if [[ -d "${ED}/usr/data" ]] ; then
379 rm -Rf "${ED}/usr/data" || die
382 if [[ -d "${ED%/}/usr/sql-bench" ]] ; then
383 mv "${ED%/}/usr/sql-bench" "${ED%/}/usr/share/mysql/" || die
386 # Unless they explicitly specific USE=test, then do not install the
387 # testsuite. It DOES have a use to be installed, esp. when you want to do a
388 # validation of your database configuration after tuning it.
390 rm -rf "${D}/${MY_SHAREDSTATEDIR}/mysql-test"
393 # Configuration stuff
394 einfo "Building default configuration ..."
395 insinto "${MY_SYSCONFDIR#${EPREFIX}}"
396 [[ -f "${S%/}/scripts/mysqlaccess.conf" ]] && doins "${S%/}"/scripts/mysqlaccess.conf
397 local mycnf_src="my.cnf-5.6"
398 sed -e "s!@DATADIR@!${MY_DATADIR}!g" \
399 "${FILESDIR%/}/${mycnf_src}" \
400 > "${TMPDIR%/}/my.cnf.ok" || die
401 use prefix && sed -i -r -e '/^user[[:space:]]*=[[:space:]]*mysql$/d' "${TMPDIR%/}/my.cnf.ok"
404 -e "/character-set/s|utf8|latin1|g" \
405 "${TMPDIR%/}/my.cnf.ok" || die
407 eprefixify "${TMPDIR%/}/my.cnf.ok"
408 newins "${TMPDIR}/my.cnf.ok" my.cnf
411 einfo "Including support files and sample configurations"
412 docinto "support-files"
415 "${S}"/support-files/magic
417 [[ -f "$script" ]] && dodoc "${script}"
421 for script in "${S}"/scripts/mysql* ; do
422 [[ ( -f "$script" ) && ( "${script%.sh}" == "${script}" ) ]] && dodoc "${script}"
426 #Remove mytop if perl is not selected
427 [[ -e "${ED}/usr/bin/mytop" ]] && ! use perl && rm -f "${ED}/usr/bin/mytop"
430 # Official test instructions:
431 # USE='perl server static-libs' \
432 # FEATURES='test userpriv -usersandbox' \
433 # ebuild mysql-X.X.XX.ebuild \
434 # digest clean package
438 local rawtestname reason
439 rawtestname="${1}" ; shift
441 ewarn "test '${rawtestname}' disabled: '${reason}'"
442 echo ${rawtestname} : ${reason} >> "${T}/disabled.def"
445 local TESTDIR="${BUILD_DIR}/mysql-test"
447 local retstatus_tests
449 if ! use server ; then
450 einfo "Skipping server tests due to minimal build."
454 # Bug #213475 - MySQL _will_ object strenously if your machine is named
455 # localhost. Also causes weird failures.
456 [[ "${HOSTNAME}" == "localhost" ]] && die "Your machine must NOT be named localhost"
458 if [[ $UID -eq 0 ]]; then
459 die "Testing with FEATURES=-userpriv is no longer supported by upstream. Tests MUST be run as non-root."
461 has usersandbox $FEATURES && ewarn "Some tests may fail with FEATURES=usersandbox"
463 einfo ">>> Test phase [test]: ${CATEGORY}/${PF}"
465 # Run CTest (test-units)
469 # Ensure that parallel runs don't die
470 export MTR_BUILD_THREAD="$((${RANDOM} % 100))"
471 # Enable parallel testing, auto will try to detect number of cores
472 # You may set this by hand.
473 # The default maximum is 8 unless MTR_MAX_PARALLEL is increased
474 export MTR_PARALLEL="${MTR_PARALLEL:-auto}"
476 # create directories because mysqladmin might run out of order
477 mkdir -p "${T}"/var-tests{,/log} || die
480 pushd "${TESTDIR}" > /dev/null || die
482 touch "${T}/disabled.def"
483 # These are failing in MySQL 5.6 for now and are believed to be
488 for t in auth_sec.keyring_udf federated.federated_plugin ; do
489 _disable_test "$t" "False positives in Gentoo"
492 if ! use latin1 ; then
494 binlog.binlog_mysqlbinlog_filter \
495 binlog.binlog_statement_insert_delayed \
496 funcs_1.is_columns_mysql \
497 funcs_1.is_tables_mysql \
498 funcs_1.is_triggers \
499 main.information_schema \
500 main.mysql_client_test \
501 main.mysqld--help-notwin \
502 perfschema.binlog_edge_mix \
503 perfschema.binlog_edge_stmt \
505 _disable_test "$t" "Requires DEFAULT_CHARSET=latin1 but USE=-latin1 is set"
509 if has_version '>=dev-libs/openssl-1.1.0' ; then
510 # Tests are expecting <openssl-1.1 default cipher
513 main.plugin_auth_sha256_tls \
522 _disable_test "$t" "Requires <dev-libs/openssl-1.1.0"
526 _disable_test main.gis-precise "Known rounding error with latest AMD processors"
528 # run mysql-test tests
529 perl mysql-test-run.pl --force --vardir="${T}/var-tests" --reorder --skip-test=tokudb --skip-test-list="${T}/disabled.def"
532 popd > /dev/null || die
534 # Cleanup is important for these testcases.
535 pkill -9 -f "${S}/ndb" 2>/dev/null
536 pkill -9 -f "${S}/sql" 2>/dev/null
539 [[ $retstatus_unit -eq 0 ]] || failures="${failures} test-unit"
540 [[ $retstatus_tests -eq 0 ]] || failures="${failures} tests"
542 [[ -z "$failures" ]] || die "Test failures: $failures"
543 einfo "Tests successfully completed"
547 MY_SHAREDSTATEDIR=${MY_SHAREDSTATEDIR="${EPREFIX}/usr/share/mysql"}
548 MY_SYSCONFDIR=${MY_SYSCONFDIR="${EPREFIX}/etc/mysql"}
549 MY_LOCALSTATEDIR=${MY_LOCALSTATEDIR="${EPREFIX}/var/lib/mysql"}
550 MY_LOGDIR=${MY_LOGDIR="${EPREFIX}/var/log/mysql"}
552 if [[ -z "${MY_DATADIR}" ]] ; then
554 if [[ -f "${MY_SYSCONFDIR}/my.cnf" ]] ; then
555 MY_DATADIR=`"my_print_defaults" mysqld 2>/dev/null \
556 | sed -ne '/datadir/s|^--datadir=||p' \
558 if [[ -z "${MY_DATADIR}" ]] ; then
559 MY_DATADIR=`grep ^datadir "${MY_SYSCONFDIR}/my.cnf" \
560 | sed -e 's/.*=\s*//' \
564 if [[ -z "${MY_DATADIR}" ]] ; then
565 MY_DATADIR="${MY_LOCALSTATEDIR}"
566 einfo "Using default MY_DATADIR"
568 elog "MySQL MY_DATADIR is ${MY_DATADIR}"
570 if [[ -z "${PREVIOUS_DATADIR}" ]] ; then
571 if [[ -e "${MY_DATADIR}" ]] ; then
572 # If you get this and you're wondering about it, see bug #207636
573 elog "MySQL datadir found in ${MY_DATADIR}"
574 elog "A new one will not be created."
575 PREVIOUS_DATADIR="yes"
577 PREVIOUS_DATADIR="no"
579 export PREVIOUS_DATADIR
582 if [[ ${EBUILD_PHASE} == "config" ]]; then
584 new_MY_DATADIR=`"my_print_defaults" mysqld 2>/dev/null \
585 | sed -ne '/datadir/s|^--datadir=||p' \
588 if [[ ( -n "${new_MY_DATADIR}" ) && ( "${new_MY_DATADIR}" != "${MY_DATADIR}" ) ]]; then
589 ewarn "MySQL MY_DATADIR has changed"
590 ewarn "from ${MY_DATADIR}"
591 ewarn "to ${new_MY_DATADIR}"
592 MY_DATADIR="${new_MY_DATADIR}"
597 export MY_SHAREDSTATEDIR MY_SYSCONFDIR
598 export MY_LOCALSTATEDIR MY_LOGDIR
604 local mypd="${EROOT%/}"/usr/bin/my_print_defaults
607 local extra_options="${3}"
608 "${mypd}" $extra_options $section | sed -n "/^${flag}/s,${flag},,gp"
610 local old_MY_DATADIR="${MY_DATADIR}"
611 local old_HOME="${HOME}"
612 # my_print_defaults needs to read stuff in $HOME/.my.cnf
613 export HOME=${EPREFIX}/root
615 # Make sure the vars are correctly initialized
618 [[ -z "${MY_DATADIR}" ]] && die "Sorry, unable to find MY_DATADIR"
619 if [[ ! -x "${EROOT%/}/usr/sbin/mysqld" ]] ; then
620 die "Minimal builds do NOT include the MySQL server"
623 if [[ ( -n "${MY_DATADIR}" ) && ( "${MY_DATADIR}" != "${old_MY_DATADIR}" ) ]]; then
624 local MY_DATADIR_s="${ROOT%/}/${MY_DATADIR}"
625 MY_DATADIR_s="${MY_DATADIR_s%%/}"
626 local old_MY_DATADIR_s="${ROOT%/}/${old_MY_DATADIR}"
627 old_MY_DATADIR_s="${old_MY_DATADIR_s%%/}"
629 if [[ ( -d "${old_MY_DATADIR_s}" ) && ( "${old_MY_DATADIR_s}" != / ) ]]; then
630 if [[ -d "${MY_DATADIR_s}" ]]; then
631 ewarn "Both ${old_MY_DATADIR_s} and ${MY_DATADIR_s} exist"
632 ewarn "Attempting to use ${MY_DATADIR_s} and preserving ${old_MY_DATADIR_s}"
634 elog "Moving MY_DATADIR from ${old_MY_DATADIR_s} to ${MY_DATADIR_s}"
635 mv --strip-trailing-slashes -T "${old_MY_DATADIR_s}" "${MY_DATADIR_s}" \
636 || die "Moving MY_DATADIR failed"
639 ewarn "Previous MY_DATADIR (${old_MY_DATADIR_s}) does not exist"
640 if [[ -d "${MY_DATADIR_s}" ]]; then
641 ewarn "Attempting to use ${MY_DATADIR_s}"
643 eerror "New MY_DATADIR (${MY_DATADIR_s}) does not exist"
644 die "Configuration Failed! Please reinstall ${CATEGORY}/${PN}"
653 if [ -z "${MYSQL_ROOT_PASSWORD}" ]; then
654 local tmp_mysqld_password_source=
656 for tmp_mysqld_password_source in mysql client; do
657 einfo "Trying to get password for mysql 'root' user from '${tmp_mysqld_password_source}' section ..."
658 MYSQL_ROOT_PASSWORD="$(_getoptval "${tmp_mysqld_password_source}" password)"
659 if [[ -n "${MYSQL_ROOT_PASSWORD}" ]]; then
660 if [[ ${MYSQL_ROOT_PASSWORD} == *$'\n'* ]]; then
661 ewarn "Ignoring password from '${tmp_mysqld_password_source}' section due to newline character (do you have multiple password options set?)!"
666 einfo "Found password in '${tmp_mysqld_password_source}' section!"
671 # Sometimes --show is required to display passwords in some implementations of my_print_defaults
672 if [[ "${MYSQL_ROOT_PASSWORD}" == '*****' ]]; then
673 MYSQL_ROOT_PASSWORD="$(_getoptval "${tmp_mysqld_password_source}" password --show)"
676 unset tmp_mysqld_password_source
678 MYSQL_TMPDIR="$(_getoptval mysqld tmpdir)"
679 # These are dir+prefix
680 MYSQL_RELAY_LOG="$(_getoptval mysqld relay-log)"
681 MYSQL_RELAY_LOG=${MYSQL_RELAY_LOG%/*}
682 MYSQL_LOG_BIN="$(_getoptval mysqld log-bin)"
683 MYSQL_LOG_BIN=${MYSQL_LOG_BIN%/*}
685 if [[ ! -d "${EROOT%/}/$MYSQL_TMPDIR" ]]; then
686 einfo "Creating MySQL tmpdir $MYSQL_TMPDIR"
687 install -d -m 770 -o mysql -g mysql "${EROOT%/}/$MYSQL_TMPDIR"
689 if [[ ! -d "${EROOT%/}/$MYSQL_LOG_BIN" ]]; then
690 einfo "Creating MySQL log-bin directory $MYSQL_LOG_BIN"
691 install -d -m 770 -o mysql -g mysql "${EROOT%/}/$MYSQL_LOG_BIN"
693 if [[ ! -d "${EROOT%/}/$MYSQL_RELAY_LOG" ]]; then
694 einfo "Creating MySQL relay-log directory $MYSQL_RELAY_LOG"
695 install -d -m 770 -o mysql -g mysql "${EROOT%/}/$MYSQL_RELAY_LOG"
698 if [[ -d "${ROOT%/}/${MY_DATADIR}/mysql" ]] ; then
699 ewarn "You have already a MySQL database in place."
700 ewarn "(${ROOT%/}/${MY_DATADIR}/*)"
701 ewarn "Please rename or delete it if you wish to replace it."
702 die "MySQL database already exists!"
705 # Bug #213475 - MySQL _will_ object strenously if your machine is named
706 # localhost. Also causes weird failures.
707 [[ "${HOSTNAME}" == "localhost" ]] && die "Your machine must NOT be named localhost"
709 if [ -z "${MYSQL_ROOT_PASSWORD}" ]; then
711 einfo "Please provide a password for the mysql 'root' user now"
712 einfo "or through the ${HOME}/.my.cnf file."
713 ewarn "Avoid [\"'\\_%] characters in the password"
714 read -rsp " >" pwd1 ; echo
716 einfo "Retype the password"
717 read -rsp " >" pwd2 ; echo
719 if [[ "x$pwd1" != "x$pwd2" ]] ; then
720 die "Passwords are not the same"
722 MYSQL_ROOT_PASSWORD="${pwd1}"
727 local sqltmp="$(emktemp)"
729 # Fix bug 446200. Don't reference host my.cnf, needs to come first,
730 # see http://bugs.mysql.com/bug.php?id=31312
731 use prefix && options="${options} '--defaults-file=${MY_SYSCONFDIR}/my.cnf'"
733 local help_tables="${EROOT%/}${MY_SHAREDSTATEDIR}/fill_help_tables.sql"
734 [[ -r "${help_tables}" ]] \
735 && cp "${help_tables}" "${TMPDIR}/fill_help_tables.sql" \
736 || touch "${TMPDIR}/fill_help_tables.sql"
737 help_tables="${TMPDIR}/fill_help_tables.sql"
739 # Figure out which options we need to disable to do the setup
740 local helpfile="${TMPDIR%/}/mysqld-help"
741 "${EROOT%/}/usr/sbin/mysqld" --verbose --help >"${helpfile}" 2>/dev/null
742 for opt in host-cache name-resolve networking slave-start \
743 federated ssl log-bin relay-log slow-query-log external-locking \
746 optexp="--(skip-)?${opt}" optfull="--loose-skip-${opt}"
747 egrep -sq -- "${optexp}" "${helpfile}" && options="${options} ${optfull}"
750 einfo "Creating the mysql database and setting proper permissions on it ..."
752 # Now that /var/run is a tmpfs mount point, we need to ensure it exists before using it
753 PID_DIR="${EROOT%/}/var/run/mysqld"
754 if [[ ! -d "${PID_DIR}" ]]; then
755 install -d -m 755 -o mysql -g mysql "${PID_DIR}" || die "Could not create pid directory"
758 if [[ ! -d "${MY_DATADIR}" ]]; then
759 install -d -m 750 -o mysql -g mysql "${MY_DATADIR}" || die "Could not create data directory"
762 pushd "${TMPDIR}" &>/dev/null || die
764 # Filling timezones, see
765 # http://dev.mysql.com/doc/mysql/en/time-zone-support.html
766 "${EROOT%/}/usr/bin/mysql_tzinfo_to_sql" "${EROOT%/}/usr/share/zoneinfo" >> "${sqltmp}" 2>/dev/null
767 chown mysql "${sqltmp}" || die
769 local cmd=( "${EROOT%/}/usr/share/mysql/scripts/mysql_install_db" )
770 [[ -f "${cmd}" ]] || cmd=( "${EROOT%/}/usr/bin/mysql_install_db" )
771 if [[ -r "${help_tables}" ]] ; then
772 cat "${help_tables}" >> "${sqltmp}"
774 cmd+=( "--basedir=${EPREFIX}/usr" ${options} "--datadir=${ROOT%/}${MY_DATADIR}" "--tmpdir=${ROOT%/}${MYSQL_TMPDIR}" )
775 einfo "Command: ${cmd[*]}"
776 su -s /bin/sh -c "${cmd[*]}" mysql \
777 >"${TMPDIR%/}"/mysql_install_db.log 2>&1
778 if [ $? -ne 0 ]; then
779 grep -B5 -A999 -i "ERROR" "${TMPDIR%/}"/mysql_install_db.log 1>&2
780 die "Failed to initialize mysqld. Please review ${EPREFIX}/var/log/mysql/mysqld.err AND ${TMPDIR%/}/mysql_install_db.log"
782 popd &>/dev/null || die
783 [[ -f "${ROOT%/}/${MY_DATADIR}/mysql/user.frm" ]] \
784 || die "MySQL databases not installed"
786 use prefix || options="${options} --user=mysql"
788 local socket="${EROOT%/}/var/run/mysqld/mysqld${RANDOM}.sock"
789 local pidfile="${EROOT%/}/var/run/mysqld/mysqld${RANDOM}.pid"
790 local mysqld="${EROOT%/}/usr/sbin/mysqld \
792 $(use prefix || echo --user=mysql) \
794 --basedir=${EROOT%/}/usr \
795 --datadir=${ROOT%/}/${MY_DATADIR} \
796 --max_allowed_packet=8M \
797 --net_buffer_length=16K \
799 --pid-file=${pidfile} \
800 --tmpdir=${ROOT}/${MYSQL_TMPDIR}"
801 #einfo "About to start mysqld: ${mysqld}"
802 ebegin "Starting mysqld"
803 einfo "Command ${mysqld}"
806 while ! [[ -S "${socket}" || "${maxtry}" -lt 1 ]] ; do
807 maxtry=$((${maxtry}-1))
813 if ! [[ -S "${socket}" ]]; then
814 die "Completely failed to start up mysqld with: ${mysqld}"
817 ebegin "Setting root password"
818 # Do this from memory, as we don't want clear text passwords in temp files
819 local sql="SET PASSWORD FOR 'root'@'localhost' = PASSWORD('${MYSQL_ROOT_PASSWORD}');"
820 "${EROOT%/}/usr/bin/mysql" \
822 "--socket=${socket}" \
827 if [[ -n "${sqltmp}" ]] ; then
828 ebegin "Loading \"zoneinfo\", this step may require a few seconds"
829 "${EROOT%/}/usr/bin/mysql" \
830 --socket="${socket}" \
833 --password="${MYSQL_ROOT_PASSWORD}" \
837 [[ $rc -ne 0 ]] && ewarn "Failed to load zoneinfo!"
840 # Stop the server and cleanup
841 einfo "Stopping the server ..."
842 kill $(< "${pidfile}" )