1 # Copyright 1999-2020 Gentoo Authors
2 # Distributed under the terms of the GNU General Public License v2
5 MY_EXTRAS_VER="20190121-0015Z"
7 #fails to build with ninja
8 CMAKE_MAKEFILE_GENERATOR=emake
10 # Keeping eutils in EAPI=6 for emktemp in pkg_config
11 inherit eutils flag-o-matic prefix toolchain-funcs java-pkg-opt-2 user cmake-utils
13 MY_PN="mysql-cluster-gpl"
14 SRC_URI="https://cdn.mysql.com/Downloads/MySQL-Cluster-7.2/${MY_PN}-${PV}.tar.gz
15 https://downloads.mysql.com/archives/MySQL-Cluster-7.2/${MY_PN}-${PV}.tar.gz"
16 # Gentoo patches to MySQL
17 if [[ "${MY_EXTRAS_VER}" != "live" && "${MY_EXTRAS_VER}" != "none" ]]; then
19 mirror://gentoo/mysql-extras-${MY_EXTRAS_VER}.tar.bz2
20 https://gitweb.gentoo.org/proj/mysql-extras.git/snapshot/mysql-extras-${MY_EXTRAS_VER}.tar.bz2"
23 HOMEPAGE="https://mysql.com/"
24 DESCRIPTION="An enhanced, drop-in replacement for MySQL"
27 IUSE="bindist client-libs debug extraengine java jemalloc latin1 libressl
28 +perl profiling selinux +server static static-libs systemtap tcmalloc
31 # Tests always fail when libressl is enabled due to hard-coded ciphers in the tests
32 RESTRICT="!bindist? ( bindist ) !test? ( test ) libressl? ( test )"
34 REQUIRED_USE="?? ( tcmalloc jemalloc )
37 KEYWORDS="~amd64 ~x86"
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
44 MY_PATCH_DIR="${WORKDIR%/}/mysql-extras"
46 EGIT_REPO_URI="git://anongit.gentoo.org/proj/mysql-extras.git"
47 EGIT_CHECKOUT_DIR="${WORKDIR%/}/mysql-extras"
48 EGIT_CLONE_TYPE=shallow
50 MY_PATCH_DIR="${WORKDIR%/}/mysql-extras-${MY_EXTRAS_VER}"
54 "${MY_PATCH_DIR}/01050_all_mysql_config_cleanup-5.5.patch"
55 "${MY_PATCH_DIR}/02040_all_embedded-library-shared-5.5.10.patch"
56 "${MY_PATCH_DIR}/20001_all_fix-minimal-build-cmake-mysql-5.5.41.patch"
57 "${MY_PATCH_DIR}/20002_all_mysql-va-list.patch"
58 "${MY_PATCH_DIR}/20006_all_cmake_elib-mysql-cluster-7.2.34.patch"
59 "${MY_PATCH_DIR}/20007_all_cmake-debug-werror-5.6.22.patch"
60 "${MY_PATCH_DIR}/20008_all_mysql-tzinfo-symlink-5.6.37.patch"
61 "${MY_PATCH_DIR}/20009_all_mysql_myodbc_symbol_fix-5.5.38.patch"
62 "${MY_PATCH_DIR}/20018_all_mysql-cluster-7.2.34-without-clientlibs-tools.patch"
63 "${MY_PATCH_DIR}/20027_all_mysql-5.5-perl5.26-includes.patch"
64 "${FILESDIR}/7.2.34-client.patch"
67 # Be warned, *DEPEND are version-dependant
68 # These are used for both runtime and compiletime
76 >=sys-apps/texinfo-4.7-r1
77 jemalloc? ( dev-libs/jemalloc:0= )
78 tcmalloc? ( dev-util/google-perftools:0= )
79 systemtap? ( >=dev-util/systemtap-1.3:0= )
81 !libressl? ( dev-libs/openssl:0= !>=dev-libs/openssl-1.1 )
82 libressl? ( dev-libs/libressl:0= )
84 >=sys-libs/zlib-1.2.3:0=
87 >=sys-libs/readline-4.1:0=
91 static? ( sys-libs/ncurses[static-libs] )
92 || ( >=sys-devel/gcc-3.4.6 >=sys-devel/gcc-apple-4.0 )
93 java? ( >=virtual/jdk-1.6 )
95 RDEPEND="selinux? ( sec-policy/selinux-mysql )
96 !dev-db/mariadb !dev-db/mariadb-galera !dev-db/percona-server !dev-db/mysql
97 server? ( !prefix? ( dev-db/mysql-init-scripts ) )
99 java? ( >=virtual/jre-1.6 )
100 perl? ( !dev-db/mytop
101 virtual/perl-Getopt-Long
103 virtual/perl-Term-ANSIColor
104 virtual/perl-Time-HiRes )
106 # For other stuff to bring us in
107 # dev-perl/DBD-mysql is needed by some scripts installed by MySQL
108 PDEPEND="perl? ( >=dev-perl/DBD-mysql-2.9004 )"
111 if [[ ${MERGE_TYPE} != binary ]] ; then
112 local GCC_MAJOR_SET=$(gcc-major-version)
113 local GCC_MINOR_SET=$(gcc-minor-version)
114 # Bug 565584. InnoDB now requires atomic functions introduced with gcc-4.7 on
115 # non x86{,_64} arches
116 if ! use amd64 && ! use x86 && [[ ${GCC_MAJOR_SET} -lt 4 || \
117 ${GCC_MAJOR_SET} -eq 4 && ${GCC_MINOR_SET} -lt 7 ]] ; then
118 eerror "${PN} needs to be built with gcc-4.7 or later."
119 eerror "Please use gcc-config to switch to gcc-4.7 or later version."
123 if has test ${FEATURES} && \
124 use server && ! has userpriv ${FEATURES} ; then
125 eerror "Testing with FEATURES=-userpriv is no longer supported by upstream. Tests MUST be run as non-root."
128 # This should come after all of the die statements
129 enewgroup mysql 60 || die "problem adding 'mysql' group"
130 enewuser mysql 60 -1 /dev/null mysql || die "problem adding 'mysql' user"
132 java-pkg-opt-2_pkg_setup
136 # Make sure the vars are correctly initialized
139 # Create log directory securely if it does not exist
140 [[ -d "${ROOT}${MY_LOGDIR}" ]] || install -d -m0750 -o mysql -g mysql "${ROOT}${MY_LOGDIR}"
143 if [[ -z "${REPLACING_VERSIONS}" ]] ; then
145 elog "You might want to run:"
146 elog "\"emerge --config =${CATEGORY}/${PF}\""
147 elog "if this is a new install."
149 elog "If you are switching server implentations, you should run the"
150 elog "mysql_upgrade tool."
154 elog "If you are upgrading major versions, you should run the"
155 elog "mysql_upgrade tool."
160 elog "Be sure to edit the my.cnf file to activate your cluster settings."
161 elog "This should be done after running \"emerge --config =${CATEGORY}/${PF}\""
162 elog "The first time the cluster is activated, you should add"
163 elog "--wsrep-new-cluster to the options in /etc/conf.d/mysql for one node."
164 elog "This option should then be removed for subsequent starts."
172 [[ "${MY_EXTRAS_VER}" == "live" ]] && S="${WORKDIR%/}/mysql-extras" git-r3_src_unpack
174 mv -f "${WORKDIR%/}/${MY_PN}-${PV}" "${S}" || die
179 echo > "${S%/}/storage/${1}/CMakeLists.txt" || die
183 echo > "${S%/}/plugin/${1}/CMakeLists.txt" || die
186 if use tcmalloc; then
187 echo "TARGET_LINK_LIBRARIES(mysqld tcmalloc)" >> "${S%/}/sql/CMakeLists.txt" || die
190 if use jemalloc; then
191 echo "TARGET_LINK_LIBRARIES(mysqld jemalloc)" >> "${S%/}/sql/CMakeLists.txt" || die
194 # Remove the centos and rhel selinux policies to support mysqld_safe under SELinux
195 if [[ -d "${S}/support-files/SELinux" ]] ; then
196 echo > "${S}/support-files/SELinux/CMakeLists.txt" || die
199 if use libressl ; then
200 sed -i 's/OPENSSL_MAJOR_VERSION STREQUAL "1"/OPENSSL_MAJOR_VERSION STREQUAL "2"/' \
201 "${S}/cmake/ssl.cmake" || die
205 local server_plugins=( semisync )
206 local test_plugins=( audit_null daemon_example fulltext )
207 if ! use server; then # These plugins are for the server
208 for plugin in "${server_plugins[@]}" ; do
209 _disable_plugin "${plugin}"
213 if ! use test; then # These plugins are only used during testing
214 for plugin in "${test_plugins[@]}" ; do
215 _disable_plugin "${plugin}"
219 # Don't build example
220 _disable_engine example
222 cmake-utils_src_prepare
223 java-pkg-opt-2_src_prepare
227 # Bug #114895, bug #110149
228 filter-flags "-O" "-O[01]"
230 append-cxxflags -felide-constructors
232 # bug #283926, with GCC4.4, this is required to get correct behavior.
233 append-flags -fno-strict-aliasing
235 CMAKE_BUILD_TYPE="RelWithDebInfo"
237 # debug hack wrt #497532
239 -DCMAKE_C_FLAGS_RELWITHDEBINFO="$(usex debug '' '-DNDEBUG')"
240 -DCMAKE_CXX_FLAGS_RELWITHDEBINFO="$(usex debug '' '-DNDEBUG')"
241 -DDEFAULT_SYSCONFDIR="${EPREFIX}/etc/mysql"
243 -DINSTALL_DOCDIR=share/doc/${PF}
244 -DINSTALL_DOCREADMEDIR=share/doc/${PF}
245 -DINSTALL_INCLUDEDIR=include/mysql
246 -DINSTALL_INFODIR=share/info
247 -DINSTALL_LIBDIR=$(get_libdir)
248 -DINSTALL_MANDIR=share/man
249 -DINSTALL_MYSQLSHAREDIR=share/mysql
250 -DINSTALL_PLUGINDIR=$(get_libdir)/mysql/plugin
251 -DINSTALL_SCRIPTDIR=share/mysql/scripts
252 -DINSTALL_MYSQLDATADIR="${EPREFIX}/var/lib/mysql"
253 -DINSTALL_SBINDIR=sbin
254 -DINSTALL_SUPPORTFILESDIR="${EPREFIX}/usr/share/mysql"
255 -DCOMPILATION_COMMENT="Gentoo Linux ${PF}"
256 -DWITH_UNIT_TESTS=$(usex test ON OFF)
258 -DENABLED_LOCAL_INFILE=1
259 -DMYSQL_UNIX_ADDR="${EPREFIX}/var/run/mysqld/mysqld.sock"
260 # The build forces this to be defined when cross-compiling. We pass it
261 # all the time for simplicity and to make sure it is actually correct.
262 -DSTACK_DIRECTION=$(tc-stack-grows-down && echo -1 || echo 1)
263 -DWITHOUT_CLIENTLIBS=YES
264 -DWITH_READLINE=$(usex bindist 1 0)
265 -DENABLE_DTRACE=$(usex systemtap)
266 -DWITH_BUNDLED_LIBEVENT=OFF
267 -DWITH_NDB_JAVA=$(usex java ON OFF)
270 mycmakeargs+=( -DINSTALL_MYSQLTESTDIR=share/mysql/mysql-test )
272 mycmakeargs+=( -DINSTALL_MYSQLTESTDIR='' )
275 if ! use yassl ; then
276 mycmakeargs+=( -DWITH_SSL=system )
278 mycmakeargs+=( -DWITH_SSL=bundled )
283 # Federated must be treated special otherwise they will not be built as plugins
284 if ! use extraengine ; then
285 mycmakeargs+=( -DWITHOUT_FEDERATED_STORAGE_ENGINE=1 )
288 if [[ ( -n ${MYSQL_DEFAULT_CHARSET} ) && ( -n ${MYSQL_DEFAULT_COLLATION} ) ]]; then
289 ewarn "You are using a custom charset of ${MYSQL_DEFAULT_CHARSET}"
290 ewarn "and a collation of ${MYSQL_DEFAULT_COLLATION}."
291 ewarn "You MUST file bugs without these variables set."
294 -DDEFAULT_CHARSET=${MYSQL_DEFAULT_CHARSET}
295 -DDEFAULT_COLLATION=${MYSQL_DEFAULT_COLLATION}
298 elif ! use latin1 ; then
300 -DDEFAULT_CHARSET=utf8
301 -DDEFAULT_COLLATION=utf8_general_ci
305 -DDEFAULT_CHARSET=latin1
306 -DDEFAULT_COLLATION=latin1_swedish_ci
310 -DINSTALL_SQLBENCHDIR=share/mysql
312 -DDISABLE_SHARED=$(usex static YES NO)
313 -DWITH_EMBEDDED_SERVER=OFF
316 if use profiling ; then
317 # Setting to OFF doesn't work: Once set, profiling options will be added
318 # to `mysqld --help` output via sql/sys_vars.cc causing
319 # "main.mysqld--help-notwin" test to fail
320 mycmakeargs+=( -DENABLED_PROFILING=ON )
324 mycmakeargs+=( -DWITH_PIC=1 )
329 -DWITH_ARCHIVE_STORAGE_ENGINE=1
330 -DWITH_BLACKHOLE_STORAGE_ENGINE=1
331 -DWITH_CSV_STORAGE_ENGINE=1
332 -DWITH_HEAP_STORAGE_ENGINE=1
333 -DWITH_INNOBASE_STORAGE_ENGINE=1
334 -DWITH_MYISAMMRG_STORAGE_ENGINE=1
335 -DWITH_MYISAM_STORAGE_ENGINE=1
336 -DWITH_PARTITION_STORAGE_ENGINE=1
342 -DEXTRA_CHARSETS=none
343 -DINSTALL_SQLBENCHDIR=
347 cmake-utils_src_configure
351 cmake-utils_src_compile
355 cmake-utils_src_install
357 # Remove an unnecessary, private config header which will never match between ABIs and is not meant to be used
358 if [[ -f "${ED%/}/usr/include/mysql/server/private/config.h" ]] ; then
359 rm "${ED%/}/usr/include/mysql/server/private/config.h" || die
362 # Make sure the vars are correctly initialized
366 einfo "Making Convenience links for mysqlcheck multi-call binary"
367 dosym "mysqlcheck" "/usr/bin/mysqlanalyze"
368 dosym "mysqlcheck" "/usr/bin/mysqlrepair"
369 dosym "mysqlcheck" "/usr/bin/mysqloptimize"
371 # INSTALL_LAYOUT=STANDALONE causes cmake to create a /usr/data dir
372 if [[ -d "${ED%/}/usr/data" ]] ; then
373 rm -Rf "${ED%/}/usr/data" || die
376 # Unless they explicitly specific USE=test, then do not install the
377 # testsuite. It DOES have a use to be installed, esp. when you want to do a
378 # validation of your database configuration after tuning it.
380 rm -rf "${D%/}/${MY_SHAREDSTATEDIR}/mysql-test"
383 # Configuration stuff
384 einfo "Building default configuration ..."
385 insinto "${MY_SYSCONFDIR#${EPREFIX}}"
386 [[ -f "${S%/}/scripts/mysqlaccess.conf" ]] && doins "${S%/}"/scripts/mysqlaccess.conf
387 local mycnf_src="my.cnf-5.5"
388 sed -e "s!@DATADIR@!${MY_DATADIR}!g" \
389 "${FILESDIR%/}/${mycnf_src}" \
390 > "${TMPDIR%/}/my.cnf.ok" || die
391 use prefix && sed -i -r -e '/^user[[:space:]]*=[[:space:]]*mysql$/d' "${TMPDIR%/}/my.cnf.ok"
394 -e "/character-set/s|utf8|latin1|g" \
395 "${TMPDIR%/}/my.cnf.ok" || die
397 eprefixify "${TMPDIR%/}/my.cnf.ok"
398 newins "${TMPDIR}/my.cnf.ok" my.cnf
401 einfo "Including support files and sample configurations"
402 docinto "support-files"
405 "${S%/}"/support-files/magic \
406 "${S%/}"/support-files/ndb-config-2-node.ini
408 [[ -f "$script" ]] && dodoc "${script}"
412 for script in "${S%/}"/scripts/mysql* ; do
413 [[ ( -f "$script" ) && ( "${script%.sh}" == "${script}" ) ]] && dodoc "${script}"
417 #Remove mytop if perl is not selected
418 [[ -e "${ED%/}/usr/bin/mytop" ]] && ! use perl && rm -f "${ED%/}/usr/bin/mytop"
421 # Official test instructions:
422 # USE='extraengine perl server' \
423 # FEATURES='test userpriv -usersandbox' \
424 # ebuild mysql-X.X.XX.ebuild \
425 # digest clean package
429 local rawtestname reason
430 rawtestname="${1}" ; shift
432 ewarn "test '${rawtestname}' disabled: '${reason}'"
433 echo ${rawtestname} : ${reason} >> "${T}/disabled.def"
436 local TESTDIR="${BUILD_DIR}/mysql-test"
438 local retstatus_tests
440 if ! use server ; then
441 einfo "Skipping server tests due to minimal build."
445 # Bug #213475 - MySQL _will_ object strenously if your machine is named
446 # localhost. Also causes weird failures.
447 [[ "${HOSTNAME}" == "localhost" ]] && die "Your machine must NOT be named localhost"
449 if [[ $UID -eq 0 ]]; then
450 die "Testing with FEATURES=-userpriv is no longer supported by upstream. Tests MUST be run as non-root."
452 has usersandbox $FEATURES && ewarn "Some tests may fail with FEATURES=usersandbox"
454 einfo ">>> Test phase [test]: ${CATEGORY}/${PF}"
456 # Run CTest (test-units)
460 # Ensure that parallel runs don't die
461 export MTR_BUILD_THREAD="$((${RANDOM} % 100))"
462 # Enable parallel testing, auto will try to detect number of cores
463 # You may set this by hand.
464 # The default maximum is 8 unless MTR_MAX_PARALLEL is increased
465 export MTR_PARALLEL="${MTR_PARALLEL:-auto}"
467 # create directories because mysqladmin might run out of order
468 mkdir -p "${T}"/var-tests{,/log} || die
471 pushd "${TESTDIR}" > /dev/null || die
473 touch "${T}/disabled.def"
474 # These are failing in MySQL 5.5 for now and are believed to be
477 # main.mysql_client_test, main.mysql_client_test_nonblock
478 # main.mysql_client_test_comp:
479 # segfaults at random under Portage only, suspect resource limits.
482 for t in main.mysql_client_test \
483 binlog.binlog_statement_insert_delayed main.information_schema \
484 main.mysqld--help-notwin main.flush_read_lock_kill \
485 sys_vars.plugin_dir_basic main.openssl_1 \
486 main.mysqlhotcopy_archive main.mysqlhotcopy_myisam \
487 ndb.ndbinfo ndb_binlog.ndb_binlog_index ; do
488 _disable_test "$t" "False positives in Gentoo"
491 _disable_test main.mysqldump "Extra expected warning not recorded in test results"
493 if ! use client-libs ; then
494 _disable_test main.plugin_auth "Needs client libraries built"
497 # run mysql-test tests
498 perl mysql-test-run.pl --force --vardir="${T}/var-tests" --reorder --skip-test=tokudb --skip-test-list="${T}/disabled.def"
501 popd > /dev/null || die
503 # Cleanup is important for these testcases.
504 pkill -9 -f "${S}/ndb" 2>/dev/null
505 pkill -9 -f "${S}/sql" 2>/dev/null
508 [[ $retstatus_unit -eq 0 ]] || failures="${failures} test-unit"
509 [[ $retstatus_tests -eq 0 ]] || failures="${failures} tests"
511 [[ -z "$failures" ]] || die "Test failures: $failures"
512 einfo "Tests successfully completed"
516 MY_SHAREDSTATEDIR=${MY_SHAREDSTATEDIR="${EPREFIX}/usr/share/mysql"}
517 MY_SYSCONFDIR=${MY_SYSCONFDIR="${EPREFIX}/etc/mysql"}
518 MY_LOCALSTATEDIR=${MY_LOCALSTATEDIR="${EPREFIX}/var/lib/mysql"}
519 MY_LOGDIR=${MY_LOGDIR="${EPREFIX}/var/log/mysql"}
521 if [[ -z "${MY_DATADIR}" ]] ; then
523 if [[ -f "${MY_SYSCONFDIR}/my.cnf" ]] ; then
524 MY_DATADIR=`"my_print_defaults" mysqld 2>/dev/null \
525 | sed -ne '/datadir/s|^--datadir=||p' \
527 if [[ -z "${MY_DATADIR}" ]] ; then
528 MY_DATADIR=`grep ^datadir "${MY_SYSCONFDIR}/my.cnf" \
529 | sed -e 's/.*=\s*//' \
533 if [[ -z "${MY_DATADIR}" ]] ; then
534 MY_DATADIR="${MY_LOCALSTATEDIR}"
535 einfo "Using default MY_DATADIR"
537 elog "MySQL MY_DATADIR is ${MY_DATADIR}"
539 if [[ -z "${PREVIOUS_DATADIR}" ]] ; then
540 if [[ -e "${MY_DATADIR}" ]] ; then
541 # If you get this and you're wondering about it, see bug #207636
542 elog "MySQL datadir found in ${MY_DATADIR}"
543 elog "A new one will not be created."
544 PREVIOUS_DATADIR="yes"
546 PREVIOUS_DATADIR="no"
548 export PREVIOUS_DATADIR
551 if [[ ${EBUILD_PHASE} == "config" ]]; then
553 new_MY_DATADIR=`"my_print_defaults" mysqld 2>/dev/null \
554 | sed -ne '/datadir/s|^--datadir=||p' \
557 if [[ ( -n "${new_MY_DATADIR}" ) && ( "${new_MY_DATADIR}" != "${MY_DATADIR}" ) ]]; then
558 ewarn "MySQL MY_DATADIR has changed"
559 ewarn "from ${MY_DATADIR}"
560 ewarn "to ${new_MY_DATADIR}"
561 MY_DATADIR="${new_MY_DATADIR}"
566 export MY_SHAREDSTATEDIR MY_SYSCONFDIR
567 export MY_LOCALSTATEDIR MY_LOGDIR
573 local mypd="${EROOT}"/usr/bin/my_print_defaults
576 local extra_options="${3}"
577 "${mypd}" $extra_options $section | sed -n "/^${flag}/s,${flag},,gp"
579 local old_MY_DATADIR="${MY_DATADIR}"
580 local old_HOME="${HOME}"
581 # my_print_defaults needs to read stuff in $HOME/.my.cnf
582 export HOME=${EPREFIX}/root
584 # Make sure the vars are correctly initialized
587 [[ -z "${MY_DATADIR}" ]] && die "Sorry, unable to find MY_DATADIR"
588 if [[ ! -x "${EROOT}/usr/sbin/mysqld" ]] ; then
589 die "Minimal builds do NOT include the MySQL server"
592 if [[ ( -n "${MY_DATADIR}" ) && ( "${MY_DATADIR}" != "${old_MY_DATADIR}" ) ]]; then
593 local MY_DATADIR_s="${ROOT}/${MY_DATADIR}"
594 MY_DATADIR_s="${MY_DATADIR_s%%/}"
595 local old_MY_DATADIR_s="${ROOT}/${old_MY_DATADIR}"
596 old_MY_DATADIR_s="${old_MY_DATADIR_s%%/}"
598 if [[ ( -d "${old_MY_DATADIR_s}" ) && ( "${old_MY_DATADIR_s}" != / ) ]]; then
599 if [[ -d "${MY_DATADIR_s}" ]]; then
600 ewarn "Both ${old_MY_DATADIR_s} and ${MY_DATADIR_s} exist"
601 ewarn "Attempting to use ${MY_DATADIR_s} and preserving ${old_MY_DATADIR_s}"
603 elog "Moving MY_DATADIR from ${old_MY_DATADIR_s} to ${MY_DATADIR_s}"
604 mv --strip-trailing-slashes -T "${old_MY_DATADIR_s}" "${MY_DATADIR_s}" \
605 || die "Moving MY_DATADIR failed"
608 ewarn "Previous MY_DATADIR (${old_MY_DATADIR_s}) does not exist"
609 if [[ -d "${MY_DATADIR_s}" ]]; then
610 ewarn "Attempting to use ${MY_DATADIR_s}"
612 eerror "New MY_DATADIR (${MY_DATADIR_s}) does not exist"
613 die "Configuration Failed! Please reinstall ${CATEGORY}/${PN}"
622 if [ -z "${MYSQL_ROOT_PASSWORD}" ]; then
623 local tmp_mysqld_password_source=
625 for tmp_mysqld_password_source in mysql client; do
626 einfo "Trying to get password for mysql 'root' user from '${tmp_mysqld_password_source}' section ..."
627 MYSQL_ROOT_PASSWORD="$(_getoptval "${tmp_mysqld_password_source}" password)"
628 if [[ -n "${MYSQL_ROOT_PASSWORD}" ]]; then
629 if [[ ${MYSQL_ROOT_PASSWORD} == *$'\n'* ]]; then
630 ewarn "Ignoring password from '${tmp_mysqld_password_source}' section due to newline character (do you have multiple password options set?)!"
635 einfo "Found password in '${tmp_mysqld_password_source}' section!"
640 # Sometimes --show is required to display passwords in some implementations of my_print_defaults
641 if [[ "${MYSQL_ROOT_PASSWORD}" == '*****' ]]; then
642 MYSQL_ROOT_PASSWORD="$(_getoptval "${tmp_mysqld_password_source}" password --show)"
645 unset tmp_mysqld_password_source
647 MYSQL_TMPDIR="$(_getoptval mysqld tmpdir)"
648 # These are dir+prefix
649 MYSQL_RELAY_LOG="$(_getoptval mysqld relay-log)"
650 MYSQL_RELAY_LOG=${MYSQL_RELAY_LOG%/*}
651 MYSQL_LOG_BIN="$(_getoptval mysqld log-bin)"
652 MYSQL_LOG_BIN=${MYSQL_LOG_BIN%/*}
654 if [[ ! -d "${ROOT}/$MYSQL_TMPDIR" ]]; then
655 einfo "Creating MySQL tmpdir $MYSQL_TMPDIR"
656 install -d -m 770 -o mysql -g mysql "${EROOT}/$MYSQL_TMPDIR"
658 if [[ ! -d "${ROOT}/$MYSQL_LOG_BIN" ]]; then
659 einfo "Creating MySQL log-bin directory $MYSQL_LOG_BIN"
660 install -d -m 770 -o mysql -g mysql "${EROOT}/$MYSQL_LOG_BIN"
662 if [[ ! -d "${EROOT}/$MYSQL_RELAY_LOG" ]]; then
663 einfo "Creating MySQL relay-log directory $MYSQL_RELAY_LOG"
664 install -d -m 770 -o mysql -g mysql "${EROOT}/$MYSQL_RELAY_LOG"
667 if [[ -d "${ROOT}/${MY_DATADIR}/mysql" ]] ; then
668 ewarn "You have already a MySQL database in place."
669 ewarn "(${ROOT}/${MY_DATADIR}/*)"
670 ewarn "Please rename or delete it if you wish to replace it."
671 die "MySQL database already exists!"
674 # Bug #213475 - MySQL _will_ object strenously if your machine is named
675 # localhost. Also causes weird failures.
676 [[ "${HOSTNAME}" == "localhost" ]] && die "Your machine must NOT be named localhost"
678 if [ -z "${MYSQL_ROOT_PASSWORD}" ]; then
680 einfo "Please provide a password for the mysql 'root' user now"
681 einfo "or through the ${HOME}/.my.cnf file."
682 ewarn "Avoid [\"'\\_%] characters in the password"
683 read -rsp " >" pwd1 ; echo
685 einfo "Retype the password"
686 read -rsp " >" pwd2 ; echo
688 if [[ "x$pwd1" != "x$pwd2" ]] ; then
689 die "Passwords are not the same"
691 MYSQL_ROOT_PASSWORD="${pwd1}"
696 local sqltmp="$(emktemp)"
698 # Fix bug 446200. Don't reference host my.cnf, needs to come first,
699 # see http://bugs.mysql.com/bug.php?id=31312
700 use prefix && options="${options} '--defaults-file=${MY_SYSCONFDIR}/my.cnf'"
702 # Figure out which options we need to disable to do the setup
703 local helpfile="${TMPDIR}/mysqld-help"
704 "${EROOT}/usr/sbin/mysqld" --verbose --help >"${helpfile}" 2>/dev/null
705 for opt in grant-tables host-cache name-resolve networking slave-start \
706 federated ssl log-bin relay-log slow-query-log external-locking \
709 optexp="--(skip-)?${opt}" optfull="--loose-skip-${opt}"
710 egrep -sq -- "${optexp}" "${helpfile}" && options="${options} ${optfull}"
713 einfo "Creating the mysql database and setting proper permissions on it ..."
715 # Now that /var/run is a tmpfs mount point, we need to ensure it exists before using it
716 PID_DIR="${EROOT}/var/run/mysqld"
717 if [[ ! -d "${PID_DIR}" ]]; then
718 install -d -m 755 -o mysql -g mysql "${PID_DIR}" || die "Could not create pid directory"
721 if [[ ! -d "${MY_DATADIR}" ]]; then
722 install -d -m 750 -o mysql -g mysql "${MY_DATADIR}" || die "Could not create data directory"
725 pushd "${TMPDIR}" &>/dev/null || die
727 # Filling timezones, see
728 # http://dev.mysql.com/doc/mysql/en/time-zone-support.html
729 "${EROOT}/usr/bin/mysql_tzinfo_to_sql" "${EROOT}/usr/share/zoneinfo" > "${sqltmp}" 2>/dev/null
731 local cmd=( "${EROOT}usr/share/mysql/scripts/mysql_install_db" )
732 [[ -f "${cmd}" ]] || cmd=( "${EROOT}usr/bin/mysql_install_db" )
733 cmd+=( "--basedir=${EPREFIX}/usr" ${options} "--datadir=${ROOT}/${MY_DATADIR}" "--tmpdir=${ROOT}/${MYSQL_TMPDIR}" )
734 einfo "Command: ${cmd[*]}"
735 su -s /bin/sh -c "${cmd[*]}" mysql \
736 >"${TMPDIR}"/mysql_install_db.log 2>&1
737 if [ $? -ne 0 ]; then
738 grep -B5 -A999 -i "ERROR" "${TMPDIR}"/mysql_install_db.log 1>&2
739 die "Failed to initialize mysqld. Please review ${EPREFIX}/var/log/mysql/mysqld.err AND ${TMPDIR}/mysql_install_db.log"
741 popd &>/dev/null || die
742 [[ -f "${ROOT}/${MY_DATADIR}/mysql/user.frm" ]] \
743 || die "MySQL databases not installed"
745 use prefix || options="${options} --user=mysql"
747 local socket="${EROOT}/var/run/mysqld/mysqld${RANDOM}.sock"
748 local pidfile="${EROOT}/var/run/mysqld/mysqld${RANDOM}.pid"
749 local mysqld="${EROOT}/usr/sbin/mysqld \
752 --basedir=${EROOT}/usr \
753 --datadir=${ROOT}/${MY_DATADIR} \
754 --max_allowed_packet=8M \
755 --net_buffer_length=16K \
757 --pid-file=${pidfile} \
758 --tmpdir=${ROOT}/${MYSQL_TMPDIR}"
759 #einfo "About to start mysqld: ${mysqld}"
760 ebegin "Starting mysqld"
761 einfo "Command ${mysqld}"
764 while ! [[ -S "${socket}" || "${maxtry}" -lt 1 ]] ; do
765 maxtry=$((${maxtry}-1))
771 if ! [[ -S "${socket}" ]]; then
772 die "Completely failed to start up mysqld with: ${mysqld}"
775 ebegin "Setting root password"
776 # Do this from memory, as we don't want clear text passwords in temp files
777 local sql="UPDATE mysql.user SET Password = PASSWORD('${MYSQL_ROOT_PASSWORD}') WHERE USER='root'; FLUSH PRIVILEGES"
778 "${EROOT}/usr/bin/mysql" \
779 "--socket=${socket}" \
784 if [[ -n "${sqltmp}" ]] ; then
785 ebegin "Loading \"zoneinfo\", this step may require a few seconds"
786 "${EROOT}/usr/bin/mysql" \
787 "--socket=${socket}" \
790 --password="${MYSQL_ROOT_PASSWORD}" \
794 [[ $rc -ne 0 ]] && ewarn "Failed to load zoneinfo!"
797 # Stop the server and cleanup
798 einfo "Stopping the server ..."
799 kill $(< "${pidfile}" )