portage-stable: Update mysql* eclasses and MariaDB Dependencies.

Updated mysql* eclasses from upstream.
Upgraded dev-db/mysql-init-scripts to version 2.0_pre1-r6 on amd64, arm, x86
Upgraded dev-db/mariadb to version 5.5.32 on amd64, arm, x86
Upgraded virtual/mysql to version 5.5 on amd64, arm, x86

BUG=chromium:332136
TEST=emerge-stumpy_moblab dev-db/mariadb

CQ-DEPEND=I13f1ab229c2e532d9ad17cf7d25216a41edfc419

Change-Id: Ica0ca76f6c35ffaf31667000b63c76cc8e96a124
Reviewed-on: https://chromium-review.googlesource.com/184009
Reviewed-by: Mike Frysinger <vapier@chromium.org>
Commit-Queue: Simran Basi <sbasi@chromium.org>
Tested-by: Simran Basi <sbasi@chromium.org>
diff --git a/dev-db/mariadb/Manifest b/dev-db/mariadb/Manifest
new file mode 100644
index 0000000..ee2d94d
--- /dev/null
+++ b/dev-db/mariadb/Manifest
@@ -0,0 +1,2 @@
+DIST mariadb-5.5.32.tar.gz 27929231 SHA256 cc76d143c60d9f24b551adaf80f694ef9beb4a6a9032c115a06f7b5c5d0ee468 SHA512 246ab7740cfdf5e9908ec437c226102e373824894813345cef7431e7ddc681b3b8081ec22d2c61bbc3e67dbe22a34b08096ffee6952f86c046b5d9fadfd79ba3 WHIRLPOOL 955098e9ea6c8cc23243e6deaef570979d201b504d20e680cf92dc11071373bf0650f6dcd455b9cbd66607659642ab2d20997b39e31d526bf691cf7ed2332742
+DIST mysql-extras-20130120-0100Z.tar.bz2 1899297 SHA256 56db6daa26070cb10b220cb06e7b4d4a84214932a5a04500ed0e76b938c01776 SHA512 9fc9b21e547ec0e1ae37b288a1ade28b11c03a89129302226c36018cf69842fda95665799ded84f04cccffaf54555acde40bf2ae6e2ea39ec63b3876382af1ba WHIRLPOOL 25f31d91d6004e7472ef6f2ff0d02b9dde9915f56fc84da600145ac09d1d56751c2ef85c897d3b7bacd29b1010b304445517452254a1e9208bc7bfa9c2e9bf2e
diff --git a/dev-db/mariadb/files/my.cnf-4.1 b/dev-db/mariadb/files/my.cnf-4.1
new file mode 100644
index 0000000..211deaa
--- /dev/null
+++ b/dev-db/mariadb/files/my.cnf-4.1
@@ -0,0 +1,147 @@
+# /etc/mysql/my.cnf: The global mysql configuration file.
+# $Header: /var/cvsroot/gentoo-x86/dev-db/mariadb/files/my.cnf-4.1,v 1.1 2010/03/15 18:47:39 robbat2 Exp $
+
+# The following options will be passed to all MySQL clients
+[client]
+#password					= your_password
+port						= 3306
+socket						= /var/run/mysqld/mysqld.sock
+
+[mysql]
+character-sets-dir=/usr/share/mysql/charsets
+default-character-set=utf8
+
+[mysqladmin]
+character-sets-dir=/usr/share/mysql/charsets
+default-character-set=utf8
+
+[mysqlcheck]
+character-sets-dir=/usr/share/mysql/charsets
+default-character-set=utf8
+
+[mysqldump]
+character-sets-dir=/usr/share/mysql/charsets
+default-character-set=utf8
+
+[mysqlimport]
+character-sets-dir=/usr/share/mysql/charsets
+default-character-set=utf8
+
+[mysqlshow]
+character-sets-dir=/usr/share/mysql/charsets
+default-character-set=utf8
+
+[myisamchk]
+character-sets-dir=/usr/share/mysql/charsets
+
+[myisampack]
+character-sets-dir=/usr/share/mysql/charsets
+
+# use [safe_mysqld] with mysql-3
+[mysqld_safe]
+err-log						= /var/log/mysql/mysql.err
+
+# add a section [mysqld-4.1] or [mysqld-5.0] for specific configurations
+[mysqld]
+character-set-server		= utf8
+default-character-set		= utf8
+user 						= mysql
+port 						= 3306
+socket 						= /var/run/mysqld/mysqld.sock
+pid-file 					= /var/run/mysqld/mysqld.pid
+log-error 					= /var/log/mysql/mysqld.err
+basedir 					= /usr
+datadir 					= @DATADIR@
+skip-locking
+key_buffer 					= 16M
+max_allowed_packet 			= 1M
+table_cache 				= 64
+sort_buffer_size 			= 512K
+net_buffer_length 			= 8K
+read_buffer_size 			= 256K
+read_rnd_buffer_size 		= 512K
+myisam_sort_buffer_size 	= 8M
+language 					= /usr/share/mysql/english
+
+# security:
+# using "localhost" in connects uses sockets by default
+# skip-networking
+bind-address				= 127.0.0.1
+
+log-bin
+server-id 					= 1
+
+# point the following paths to different dedicated disks
+tmpdir 						= /tmp/
+#log-update 				= /path-to-dedicated-directory/hostname
+
+# you need the debug USE flag enabled to use the following directives,
+# if needed, uncomment them, start the server and issue 
+# #tail -f /tmp/mysqld.sql /tmp/mysqld.trace
+# this will show you *exactly* what's happening in your server ;)
+
+#log						= /tmp/mysqld.sql
+#gdb
+#debug						= d:t:i:o,/tmp/mysqld.trace
+#one-thread
+
+# uncomment the following directives if you are using BDB tables
+#bdb_cache_size				= 4M
+#bdb_max_lock				= 10000
+
+# the following is the InnoDB configuration
+# if you wish to disable innodb instead
+# uncomment just the next line
+#skip-innodb
+#
+# the rest of the innodb config follows:
+# don't eat too much memory, we're trying to be safe on 64Mb boxes
+# you might want to bump this up a bit on boxes with more RAM
+innodb_buffer_pool_size = 16M
+# this is the default, increase it if you have lots of tables
+innodb_additional_mem_pool_size = 2M
+#
+# i'd like to use /var/lib/mysql/innodb, but that is seen as a database :-(
+# and upstream wants things to be under /var/lib/mysql/, so that's the route
+# we have to take for the moment
+#innodb_data_home_dir		= /var/lib/mysql/
+#innodb_log_arch_dir		= /var/lib/mysql/
+#innodb_log_group_home_dir	= /var/lib/mysql/
+# you may wish to change this size to be more suitable for your system
+# the max is there to avoid run-away growth on your machine
+innodb_data_file_path = ibdata1:10M:autoextend:max:128M
+# we keep this at around 25% of of innodb_buffer_pool_size
+# sensible values range from 1MB to (1/innodb_log_files_in_group*innodb_buffer_pool_size)
+innodb_log_file_size = 5M
+# this is the default, increase it if you have very large transactions going on
+innodb_log_buffer_size = 8M
+# this is the default and won't hurt you
+# you shouldn't need to tweak it
+set-variable = innodb_log_files_in_group=2
+# see the innodb config docs, the other options are not always safe
+innodb_flush_log_at_trx_commit = 1
+innodb_lock_wait_timeout = 50
+innodb_file_per_table
+
+[mysqldump]
+quick
+max_allowed_packet 			= 16M
+
+[mysql]
+# uncomment the next directive if you are not familiar with SQL
+#safe-updates
+
+[isamchk]
+key_buffer 					= 20M
+sort_buffer_size 			= 20M
+read_buffer 				= 2M
+write_buffer 				= 2M
+
+[myisamchk]
+key_buffer 					= 20M
+sort_buffer_size 			= 20M
+read_buffer 				= 2M
+write_buffer 				= 2M
+
+[mysqlhotcopy]
+interactive-timeout
diff --git a/dev-db/mariadb/files/my.cnf-5.1 b/dev-db/mariadb/files/my.cnf-5.1
new file mode 100644
index 0000000..baf41c5
--- /dev/null
+++ b/dev-db/mariadb/files/my.cnf-5.1
@@ -0,0 +1,146 @@
+# @GENTOO_PORTAGE_EPREFIX@/etc/mysql/my.cnf: The global mysql configuration file.
+# $Header: /var/cvsroot/gentoo-x86/dev-db/mariadb/files/my.cnf-5.1,v 1.3 2013/01/20 02:39:55 robbat2 Exp $
+
+# The following options will be passed to all MySQL clients
+[client]
+#password					= your_password
+port						= 3306
+socket						= @GENTOO_PORTAGE_EPREFIX@/var/run/mysqld/mysqld.sock
+
+[mysql]
+character-sets-dir=@GENTOO_PORTAGE_EPREFIX@/usr/share/mysql/charsets
+default-character-set=utf8
+
+[mysqladmin]
+character-sets-dir=@GENTOO_PORTAGE_EPREFIX@/usr/share/mysql/charsets
+default-character-set=utf8
+
+[mysqlcheck]
+character-sets-dir=@GENTOO_PORTAGE_EPREFIX@/usr/share/mysql/charsets
+default-character-set=utf8
+
+[mysqldump]
+character-sets-dir=@GENTOO_PORTAGE_EPREFIX@/usr/share/mysql/charsets
+default-character-set=utf8
+
+[mysqlimport]
+character-sets-dir=@GENTOO_PORTAGE_EPREFIX@/usr/share/mysql/charsets
+default-character-set=utf8
+
+[mysqlshow]
+character-sets-dir=@GENTOO_PORTAGE_EPREFIX@/usr/share/mysql/charsets
+default-character-set=utf8
+
+[myisamchk]
+character-sets-dir=@GENTOO_PORTAGE_EPREFIX@/usr/share/mysql/charsets
+
+[myisampack]
+character-sets-dir=@GENTOO_PORTAGE_EPREFIX@/usr/share/mysql/charsets
+
+# use [safe_mysqld] with mysql-3
+[mysqld_safe]
+err-log						= @GENTOO_PORTAGE_EPREFIX@/var/log/mysql/mysql.err
+
+# add a section [mysqld-4.1] or [mysqld-5.0] for specific configurations
+[mysqld]
+character-set-server		= utf8
+user 						= mysql
+port 						= 3306
+socket 						= @GENTOO_PORTAGE_EPREFIX@/var/run/mysqld/mysqld.sock
+pid-file 					= @GENTOO_PORTAGE_EPREFIX@/var/run/mysqld/mysqld.pid
+log-error 					= @GENTOO_PORTAGE_EPREFIX@/var/log/mysql/mysqld.err
+basedir 					= @GENTOO_PORTAGE_EPREFIX@/usr
+datadir 					= @DATADIR@
+skip-external-locking
+key_buffer 					= 16M
+max_allowed_packet 			= 1M
+table_open_cache 			= 64
+sort_buffer_size 			= 512K
+net_buffer_length 			= 8K
+read_buffer_size 			= 256K
+read_rnd_buffer_size 		= 512K
+myisam_sort_buffer_size 	= 8M
+language 					= @GENTOO_PORTAGE_EPREFIX@/usr/share/mysql/english
+
+# security:
+# using "localhost" in connects uses sockets by default
+# skip-networking
+bind-address				= 127.0.0.1
+
+log-bin
+server-id 					= 1
+
+# point the following paths to different dedicated disks
+tmpdir 						= @GENTOO_PORTAGE_EPREFIX@/tmp/
+#log-update 				= @GENTOO_PORTAGE_EPREFIX@/path-to-dedicated-directory/hostname
+
+# you need the debug USE flag enabled to use the following directives,
+# if needed, uncomment them, start the server and issue 
+# #tail -f @GENTOO_PORTAGE_EPREFIX@/tmp/mysqld.sql @GENTOO_PORTAGE_EPREFIX@/tmp/mysqld.trace
+# this will show you *exactly* what's happening in your server ;)
+
+#log						= @GENTOO_PORTAGE_EPREFIX@/tmp/mysqld.sql
+#gdb
+#debug						= d:t:i:o,/tmp/mysqld.trace
+#one-thread
+
+# uncomment the following directives if you are using BDB tables
+#bdb_cache_size				= 4M
+#bdb_max_lock				= 10000
+
+# the following is the InnoDB configuration
+# if you wish to disable innodb instead
+# uncomment just the next line
+#skip-innodb
+#
+# the rest of the innodb config follows:
+# don't eat too much memory, we're trying to be safe on 64Mb boxes
+# you might want to bump this up a bit on boxes with more RAM
+innodb_buffer_pool_size = 16M
+# this is the default, increase it if you have lots of tables
+innodb_additional_mem_pool_size = 2M
+#
+# i'd like to use @GENTOO_PORTAGE_EPREFIX@/var/lib/mysql/innodb, but that is seen as a database :-(
+# and upstream wants things to be under @GENTOO_PORTAGE_EPREFIX@/var/lib/mysql/, so that's the route
+# we have to take for the moment
+#innodb_data_home_dir		= @GENTOO_PORTAGE_EPREFIX@/var/lib/mysql/
+#innodb_log_arch_dir		= @GENTOO_PORTAGE_EPREFIX@/var/lib/mysql/
+#innodb_log_group_home_dir	= @GENTOO_PORTAGE_EPREFIX@/var/lib/mysql/
+# you may wish to change this size to be more suitable for your system
+# the max is there to avoid run-away growth on your machine
+innodb_data_file_path = ibdata1:10M:autoextend:max:128M
+# we keep this at around 25% of of innodb_buffer_pool_size
+# sensible values range from 1MB to (1/innodb_log_files_in_group*innodb_buffer_pool_size)
+innodb_log_file_size = 5M
+# this is the default, increase it if you have very large transactions going on
+innodb_log_buffer_size = 8M
+# this is the default and won't hurt you
+# you shouldn't need to tweak it
+innodb_log_files_in_group=2
+# see the innodb config docs, the other options are not always safe
+innodb_flush_log_at_trx_commit = 1
+innodb_lock_wait_timeout = 50
+innodb_file_per_table
+
+[mysqldump]
+quick
+max_allowed_packet 			= 16M
+
+[mysql]
+# uncomment the next directive if you are not familiar with SQL
+#safe-updates
+
+[isamchk]
+key_buffer 					= 20M
+sort_buffer_size 			= 20M
+read_buffer 				= 2M
+write_buffer 				= 2M
+
+[myisamchk]
+key_buffer 					= 20M
+sort_buffer_size 			= 20M
+read_buffer 				= 2M
+write_buffer 				= 2M
+
+[mysqlhotcopy]
+interactive-timeout
diff --git a/dev-db/mariadb/files/my.cnf-5.5 b/dev-db/mariadb/files/my.cnf-5.5
new file mode 100644
index 0000000..1f42561
--- /dev/null
+++ b/dev-db/mariadb/files/my.cnf-5.5
@@ -0,0 +1,153 @@
+# @GENTOO_PORTAGE_EPREFIX@/etc/mysql/my.cnf: The global mysql configuration file.
+# $Header: /var/cvsroot/gentoo-x86/dev-db/mariadb/files/my.cnf-5.5,v 1.2 2013/01/20 02:39:55 robbat2 Exp $
+
+# The following options will be passed to all MySQL clients
+[client]
+#password					= your_password
+port						= 3306
+socket						= @GENTOO_PORTAGE_EPREFIX@/var/run/mysqld/mysqld.sock
+
+[mysql]
+character-sets-dir=@GENTOO_PORTAGE_EPREFIX@/usr/share/mysql/charsets
+default-character-set=utf8
+
+[mysqladmin]
+character-sets-dir=@GENTOO_PORTAGE_EPREFIX@/usr/share/mysql/charsets
+default-character-set=utf8
+
+[mysqlcheck]
+character-sets-dir=@GENTOO_PORTAGE_EPREFIX@/usr/share/mysql/charsets
+default-character-set=utf8
+
+[mysqldump]
+character-sets-dir=@GENTOO_PORTAGE_EPREFIX@/usr/share/mysql/charsets
+default-character-set=utf8
+
+[mysqlimport]
+character-sets-dir=@GENTOO_PORTAGE_EPREFIX@/usr/share/mysql/charsets
+default-character-set=utf8
+
+[mysqlshow]
+character-sets-dir=@GENTOO_PORTAGE_EPREFIX@/usr/share/mysql/charsets
+default-character-set=utf8
+
+[myisamchk]
+character-sets-dir=@GENTOO_PORTAGE_EPREFIX@/usr/share/mysql/charsets
+
+[myisampack]
+character-sets-dir=@GENTOO_PORTAGE_EPREFIX@/usr/share/mysql/charsets
+
+# use [safe_mysqld] with mysql-3
+[mysqld_safe]
+err-log						= @GENTOO_PORTAGE_EPREFIX@/var/log/mysql/mysql.err
+
+# add a section [mysqld-4.1] or [mysqld-5.0] for specific configurations
+[mysqld]
+character-set-server		= utf8
+user 						= mysql
+port 						= 3306
+socket 						= @GENTOO_PORTAGE_EPREFIX@/var/run/mysqld/mysqld.sock
+pid-file 					= @GENTOO_PORTAGE_EPREFIX@/var/run/mysqld/mysqld.pid
+log-error 					= @GENTOO_PORTAGE_EPREFIX@/var/log/mysql/mysqld.err
+basedir 					= @GENTOO_PORTAGE_EPREFIX@/usr
+datadir 					= @DATADIR@
+skip-external-locking
+key_buffer 					= 16M
+max_allowed_packet 			= 1M
+table_open_cache 			= 64
+sort_buffer_size 			= 512K
+net_buffer_length 			= 8K
+read_buffer_size 			= 256K
+read_rnd_buffer_size 		= 512K
+myisam_sort_buffer_size 	= 8M
+lc_messages_dir			= @GENTOO_PORTAGE_EPREFIX@/usr/share/mysql
+#Set this to your desired error message language
+lc_messages			= en_US
+
+# security:
+# using "localhost" in connects uses sockets by default
+# skip-networking
+bind-address				= 127.0.0.1
+
+log-bin
+server-id 					= 1
+
+# point the following paths to different dedicated disks
+tmpdir 						= @GENTOO_PORTAGE_EPREFIX@/tmp/
+#log-update 				= @GENTOO_PORTAGE_EPREFIX@/path-to-dedicated-directory/hostname
+
+# you need the debug USE flag enabled to use the following directives,
+# if needed, uncomment them, start the server and issue 
+# #tail -f @GENTOO_PORTAGE_EPREFIX@/tmp/mysqld.sql @GENTOO_PORTAGE_EPREFIX@/tmp/mysqld.trace
+# this will show you *exactly* what's happening in your server ;)
+
+#log						= @GENTOO_PORTAGE_EPREFIX@/tmp/mysqld.sql
+#gdb
+#debug						= d:t:i:o,/tmp/mysqld.trace
+#one-thread
+
+# uncomment the following directives if you are using BDB tables
+#bdb_cache_size				= 4M
+#bdb_max_lock				= 10000
+
+# the following is the InnoDB configuration
+# if you wish to disable innodb instead
+# uncomment just the next line
+#skip-innodb
+#
+# the rest of the innodb config follows:
+# don't eat too much memory, we're trying to be safe on 64Mb boxes
+# you might want to bump this up a bit on boxes with more RAM
+innodb_buffer_pool_size = 16M
+# this is the default, increase it if you have lots of tables
+innodb_additional_mem_pool_size = 2M
+#
+# i'd like to use @GENTOO_PORTAGE_EPREFIX@/var/lib/mysql/innodb, but that is seen as a database :-(
+# and upstream wants things to be under @GENTOO_PORTAGE_EPREFIX@/var/lib/mysql/, so that's the route
+# we have to take for the moment
+#innodb_data_home_dir		= @GENTOO_PORTAGE_EPREFIX@/var/lib/mysql/
+#innodb_log_arch_dir		= @GENTOO_PORTAGE_EPREFIX@/var/lib/mysql/
+#innodb_log_group_home_dir	= @GENTOO_PORTAGE_EPREFIX@/var/lib/mysql/
+# you may wish to change this size to be more suitable for your system
+# the max is there to avoid run-away growth on your machine
+innodb_data_file_path = ibdata1:10M:autoextend:max:128M
+# we keep this at around 25% of of innodb_buffer_pool_size
+# sensible values range from 1MB to (1/innodb_log_files_in_group*innodb_buffer_pool_size)
+innodb_log_file_size = 5M
+# this is the default, increase it if you have very large transactions going on
+innodb_log_buffer_size = 8M
+# this is the default and won't hurt you
+# you shouldn't need to tweak it
+innodb_log_files_in_group=2
+# see the innodb config docs, the other options are not always safe
+innodb_flush_log_at_trx_commit = 1
+innodb_lock_wait_timeout = 50
+innodb_file_per_table
+
+# Uncomment this to get FEDERATED engine support
+#plugin-load=federated=ha_federated.so
+loose-federated
+
+[mysqldump]
+quick
+max_allowed_packet 			= 16M
+
+[mysql]
+# uncomment the next directive if you are not familiar with SQL
+#safe-updates
+
+[isamchk]
+key_buffer 					= 20M
+sort_buffer_size 			= 20M
+read_buffer 				= 2M
+write_buffer 				= 2M
+
+[myisamchk]
+key_buffer 					= 20M
+sort_buffer_size 			= 20M
+read_buffer 				= 2M
+write_buffer 				= 2M
+
+[mysqlhotcopy]
+interactive-timeout
+
diff --git a/dev-db/mariadb/mariadb-5.5.32.ebuild b/dev-db/mariadb/mariadb-5.5.32.ebuild
new file mode 100644
index 0000000..d5ea968
--- /dev/null
+++ b/dev-db/mariadb/mariadb-5.5.32.ebuild
@@ -0,0 +1,128 @@
+# Copyright 1999-2013 Gentoo Foundation
+# Distributed under the terms of the GNU General Public License v2
+# $Header: /var/cvsroot/gentoo-x86/dev-db/mariadb/mariadb-5.5.32.ebuild,v 1.1 2013/09/04 20:38:02 jmbsvicetto Exp $
+
+EAPI="4"
+MY_EXTRAS_VER="20130120-0100Z"
+
+# Build system
+BUILD="cmake"
+
+inherit toolchain-funcs mysql-v2
+# only to make repoman happy. it is really set in the eclass
+IUSE="$IUSE"
+
+# REMEMBER: also update eclass/mysql*.eclass before committing!
+KEYWORDS="*"
+
+# When MY_EXTRAS is bumped, the index should be revised to exclude these.
+EPATCH_EXCLUDE=''
+
+DEPEND="|| ( >=sys-devel/gcc-3.4.6 >=sys-devel/gcc-apple-4.0 )"
+RDEPEND="${RDEPEND}"
+
+# Please do not add a naive src_unpack to this ebuild
+# If you want to add a single patch, copy the ebuild to an overlay
+# and create your own mysql-extras tarball, looking at 000_index.txt
+
+# Official test instructions:
+# USE='berkdb -cluster embedded extraengine perl ssl community' \
+# FEATURES='test userpriv -usersandbox' \
+# ebuild mariadb-X.X.XX.ebuild \
+# digest clean package
+src_test() {
+
+	local TESTDIR="${CMAKE_BUILD_DIR}/mysql-test"
+	local retstatus_unit
+	local retstatus_tests
+
+	# Bug #213475 - MySQL _will_ object strenously if your machine is named
+	# localhost. Also causes weird failures.
+	[[ "${HOSTNAME}" == "localhost" ]] && die "Your machine must NOT be named localhost"
+
+	if ! use "minimal" ; then
+
+		if [[ $UID -eq 0 ]]; then
+			die "Testing with FEATURES=-userpriv is no longer supported by upstream. Tests MUST be run as non-root."
+		fi
+		has usersandbox $FEATURES && eerror "Some tests may fail with FEATURES=usersandbox"
+
+		einfo ">>> Test phase [test]: ${CATEGORY}/${PF}"
+		addpredict /this-dir-does-not-exist/t9.MYI
+
+		# Run CTest (test-units)
+		cmake-utils_src_test
+		retstatus_unit=$?
+		[[ $retstatus_unit -eq 0 ]] || eerror "test-unit failed"
+
+		# Ensure that parallel runs don't die
+		export MTR_BUILD_THREAD="$((${RANDOM} % 100))"
+
+		# create directories because mysqladmin might right out of order
+		mkdir -p "${S}"/mysql-test/var-tests{,/log}
+
+		# These are failing in MySQL 5.5 for now and are believed to be
+		# false positives:
+		#
+		# main.information_schema, binlog.binlog_statement_insert_delayed,
+		# main.mysqld--help, funcs_1.is_triggers, funcs_1.is_tables_mysql,
+		# funcs_1.is_columns_mysql
+		# fails due to USE=-latin1 / utf8 default
+		#
+		# main.mysql_client_test, main.mysql_client_test_nonblock:
+		# segfaults at random under Portage only, suspect resource limits.
+		#
+		# sys_vars.plugin_dir_basic
+		# fails because PLUGIN_DIR is set to MYSQL_LIBDIR64/plugin
+		# instead of MYSQL_LIBDIR/plugin
+		#
+		# main.flush_read_lock_kill
+		# fails because of unknown system variable 'DEBUG_SYNC'
+		#
+		# main.openssl_1
+		# error message changing
+		# -mysqltest: Could not open connection 'default': 2026 SSL connection
+		#  error: ASN: bad other signature confirmation
+		# +mysqltest: Could not open connection 'default': 2026 SSL connection
+		#  error: error:00000001:lib(0):func(0):reason(1)
+		#
+		# plugins.unix_socket
+		# fails because portage strips out the USER enviornment variable
+		#
+
+		for t in main.mysql_client_test main.mysql_client_test_nonblock \
+			binlog.binlog_statement_insert_delayed main.information_schema \
+			main.mysqld--help main.flush_read_lock_kill \
+			sys_vars.plugin_dir_basic main.openssl_1 plugins.unix_socket \
+			funcs_1.is_triggers funcs_1.is_tables_mysql funcs_1.is_columns_mysql ; do
+				mysql-v2_disable_test  "$t" "False positives in Gentoo"
+		done
+
+		# Run mysql tests
+		pushd "${TESTDIR}"
+
+		# run mysql-test tests
+		perl mysql-test-run.pl --force --vardir="${S}/mysql-test/var-tests"
+		retstatus_tests=$?
+		[[ $retstatus_tests -eq 0 ]] || eerror "tests failed"
+		has usersandbox $FEATURES && eerror "Some tests may fail with FEATURES=usersandbox"
+
+		popd
+
+		# Cleanup is important for these testcases.
+		pkill -9 -f "${S}/ndb" 2>/dev/null
+		pkill -9 -f "${S}/sql" 2>/dev/null
+
+		failures=""
+		[[ $retstatus_unit -eq 0 ]] || failures="${failures} test-unit"
+		[[ $retstatus_tests -eq 0 ]] || failures="${failures} tests"
+		has usersandbox $FEATURES && eerror "Some tests may fail with FEATURES=usersandbox"
+
+		[[ -z "$failures" ]] || die "Test failures: $failures"
+		einfo "Tests successfully completed"
+
+	else
+
+		einfo "Skipping server tests due to minimal build."
+	fi
+}
diff --git a/dev-db/mariadb/metadata.xml b/dev-db/mariadb/metadata.xml
new file mode 100644
index 0000000..8fb0475
--- /dev/null
+++ b/dev-db/mariadb/metadata.xml
@@ -0,0 +1,28 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!DOCTYPE pkgmetadata SYSTEM "http://www.gentoo.org/dtd/metadata.dtd">
+<pkgmetadata>
+<herd>mysql</herd>
+<!-- 
+Please note that this list is shared between the following packages:
+dev-db/mysql
+dev-db/mariadb
+-->
+<use>
+  <flag name='big-tables'>Make tables contain up to 1.844E+19 rows</flag>
+  <flag name='cluster'>Add support for NDB clustering (deprecated)</flag>
+  <flag name='community'>Enables the community features from upstream.</flag>
+  <flag name='embedded'>Build embedded server (libmysqld)</flag>
+  <flag name='extraengine'>Add support for alternative storage engines (Archive, CSV, Blackhole, Federated(X), Partition)</flag>
+  <flag name="jemalloc">Use <pkg>dev-libs/jemalloc</pkg> for allocations.</flag>
+  <flag name='latin1'>Use LATIN1 encoding instead of UTF8</flag>
+  <flag name='libevent'>Use libevent for connection handling</flag>
+  <flag name='max-idx-128'>Raise the max index per table limit from 64 to 128</flag>
+  <flag name='minimal'>Install client programs only, no server</flag>
+  <flag name='oqgraph'>Add support for the Open Query GRAPH engine</flag>
+  <flag name='pbxt'>Add experimental support for PBXT storage engine</flag>
+  <flag name='profiling'>Add support for statement profiling (requires USE=community).</flag>
+  <flag name="systemtap">Build support for profiling and tracing using <pkg>dev-util/systemtap</pkg></flag>
+  <flag name='sphinx'>Add suport for the sphinx full-text search engine</flag>
+  <flag name='test'>Install upstream testsuites for end use.</flag>
+</use>
+</pkgmetadata>
diff --git a/dev-db/mysql-init-scripts/files/logrotate.mysql b/dev-db/mysql-init-scripts/files/logrotate.mysql
new file mode 100644
index 0000000..3399e30
--- /dev/null
+++ b/dev-db/mysql-init-scripts/files/logrotate.mysql
@@ -0,0 +1,15 @@
+# Copyright 1999-2011 Gentoo Foundation
+# Distributed under the terms of the GNU General Public License v2
+# $Header: /var/cvsroot/gentoo-x86/dev-db/mysql-init-scripts/files/logrotate.mysql,v 1.2 2011/01/13 20:06:06 robbat2 Exp $
+
+/var/log/mysql/mysql.err /var/log/mysql/mysql.log /var/log/mysql/mysqld.err {
+monthly
+create 660 mysql mysql
+notifempty
+size 5M
+sharedscripts
+missingok
+postrotate
+[ -f /var/run/mysqld/mysqld.pid ] && /bin/kill -HUP `cat /var/run/mysqld/mysqld.pid`
+endscript
+}
diff --git a/dev-db/mysql-init-scripts/files/mysql-5.1.53-conf.d b/dev-db/mysql-init-scripts/files/mysql-5.1.53-conf.d
new file mode 100644
index 0000000..df4c3a4
--- /dev/null
+++ b/dev-db/mysql-init-scripts/files/mysql-5.1.53-conf.d
@@ -0,0 +1,79 @@
+# Copyright 1999-2011 Gentoo Foundation
+# Distributed under the terms of the GNU General Public License v2
+# $Header: /var/cvsroot/gentoo-x86/dev-db/mysql-init-scripts/files/mysql-5.1.53-conf.d,v 1.2 2011/01/15 17:54:31 robbat2 Exp $
+
+# If you want a non-stock location for the config file, uncomment or update
+# either of these as needed. If you do use it, you must make sure that none of
+# your socket, pidfile, datadir, logfiles, binary logs, relay logs or InnoDB
+# files collide with each other.
+MY_CNF="/etc/mysql/my.cnf"
+#MY_CNF="${MY_CNF:-/etc/${SVCNAME}/my.cnf}"
+#MY_CNF="${MY_CNF:-/etc/mysql/my-${SVCNAME/mysql.}.cnf}"
+
+# Place any additional arguments here that you might need
+# Common/useful options:
+# --skip-slave-start=1 - For bringing up replication initially
+# --server-id=NNN - Server ID for replication
+# --skip-networking - lock it down to UNIX sockets only
+MY_ARGS=""
+
+# This setting (in seconds) should be high enough to allow InnoDB to do a full
+# checkpoint recovery. 900 is the default used in the upstream RPM startup
+# scripts. 30 seconds should be sufficent if you just have a tiny <1GiB
+# database. After the core startup is done, we wait this long for the UNIX
+# socket to appear.
+STARTUP_TIMEOUT="900"
+
+# This is how long, in milliseconds, we wait for pidfile to be created, early
+# in the startup.
+STARTUP_EARLY_TIMEOUT="1000"
+
+# How long (in seconds) should we wait for shutdown?
+STOP_TIMEOUT=120
+
+# integer [-20 .. 19 ] default 0
+# change the priority of the server -20 (high) to 19 (low)
+# see nice(1) for description
+#NICE=0
+
+# See start-stop-daemon(8) for possible settings
+#IONICE=2
+
+# If defined, --verbose gets passed to S-S-D
+#DEBUG=1
+
+# Depending on your usage of MySQL, you may also wish to start it after some
+# other services are up. Uncomment the lines below as needed. If these aren't
+# enough for you, we encourage you to file a bug, and help us understand how
+# you are using MySQL.
+
+# Do your MySQL ACLs refer to hostnames not in your /etc/hosts?
+# If so, you need DNS before you can accept connections.
+# Avoid dependency circular loops if you use MySQL to power a local DNS server.
+#rc_use="dns"
+#rc_after="dns"
+
+# Does your MySQL bind to an IP on an interface other than net.lo?
+# Alternatively you might wish to specify the exact interface here.
+#rc_use="net"
+#rc_after="net"
+
+# Do you store your MySQL files on a SAN or other network filesystem, that is
+# provided by the netmount init script?
+#rc_need="netmount"
+
+# Or from NFS? P.S. This is not a good idea in most cases, but does have some
+# valid usage cases, so we provide the option.
+#rc_need="nfsmount"
+
+# Should any one of the instances satisfy the requirement for MySQL coming up?
+# By default, we say no.
+[ "${SVCNAME}" != mysql ] && rc_provide="!mysql"
+# But uncomment this next instead if you think it should.
+#rc_provide="mysql"
+
+# The conditional above has a false-positive "failure" return value as a
+# side-effect, and since it's the last statement, without the next line, this
+# script returns failure.
+return 0
+# vim: ft=gentoo-conf-d et ts=4 sw=4:
diff --git a/dev-db/mysql-init-scripts/files/mysql-5.1.53-init.d b/dev-db/mysql-init-scripts/files/mysql-5.1.53-init.d
new file mode 100644
index 0000000..d824b6a
--- /dev/null
+++ b/dev-db/mysql-init-scripts/files/mysql-5.1.53-init.d
@@ -0,0 +1,121 @@
+#!/sbin/runscript
+# Copyright 1999-2011 Gentoo Foundation
+# Distributed under the terms of the GNU General Public License v2
+# $Header: /var/cvsroot/gentoo-x86/dev-db/mysql-init-scripts/files/mysql-5.1.53-init.d,v 1.1 2011/01/13 20:06:06 robbat2 Exp $
+
+depend() {
+	use net.lo
+	# localmount needed for $basedir
+	need localmount
+}
+
+get_config() {
+	my_print_defaults --config-file="$1" mysqld |
+	sed -n -e "s/^--$2=//p"
+}
+
+mysql_svcname() {
+	local ebextra=
+	case "${SVCNAME}" in
+		mysql*) ;;
+		*) ebextra=" (mysql)" ;;
+	esac
+	echo "${SVCNAME}${ebextra}"
+}
+
+start() {
+	# Check for old conf.d variables that mean migration was not yet done.
+	local varlist="${!mysql_slot_*} ${!MYSQL_BLOG_PID_FILE*} ${!STOPTIMEOUT*}"
+	varlist="${varlist// /}"
+	# Yes, MYSQL_INIT_I_KNOW_WHAT_I_AM_DOING is a hidden variable.
+	# It does have a use in testing, as it is possible to build a config file
+	# that works with both the old and new init scripts simulateously.
+	if [ -n "${varlist}" -a -z "${MYSQL_INIT_I_KNOW_WHAT_I_AM_DOING}" ]; then
+		eerror "You have not updated your conf.d for the new mysql-init-scripts-2 revamp."
+		eerror "Not proceeding because it may be dangerous."
+		return 1
+	fi
+
+	# Now we can startup
+	ebegin "Starting $(mysql_svcname)"
+
+	MY_CNF="${MY_CNF:-/etc/${SVCNAME}/my.cnf}"
+
+	if [ ! -r "${MY_CNF}" ] ; then
+		eerror "Cannot read the configuration file \`${MY_CNF}'"
+		return 1
+	fi
+
+	# tail -n1 is critical as these we only want the last instance of the option
+	local basedir=$(get_config "${MY_CNF}" basedir | tail -n1)
+	local datadir=$(get_config "${MY_CNF}" datadir | tail -n1)
+	local pidfile=$(get_config "${MY_CNF}" pid-file | tail -n1)
+	local socket=$(get_config "${MY_CNF}" socket | tail -n1)
+
+	if [ ! -d "${datadir}" ] ; then
+		eerror "MySQL datadir \`${datadir}' is empty or invalid"
+		eerror "Please check your config file \`${MY_CNF}'"
+		return 1
+	fi
+
+	if [ ! -d "${datadir}"/mysql ] ; then
+		eerror "You don't appear to have the mysql database installed yet."
+		eerror "Please run /usr/bin/mysql_install_db to have this done..."
+		return 1
+	fi
+
+	local piddir="${pidfile%/*}"
+	if [ ! -d "$piddir" ] ; then
+		mkdir "$piddir" && \
+		chown mysql "$piddir"
+		rc=$?
+		if [ $rc -ne 0 ]; then
+			eerror "Directory $piddir for pidfile does not exist and cannot be created"
+			return 1
+		fi
+	fi
+
+	local startup_timeout=${STARTUP_TIMEOUT:-900}
+	local startup_early_timeout=${STARTUP_EARLY_TIMEOUT:-1000}
+	local tmpnice="${NICE:+"--nicelevel "}${NICE}"
+	local tmpionice="${IONICE:+"--ionice "}${IONICE}"
+	start-stop-daemon \
+		${DEBUG/*/"--verbose"} \
+		--start \
+		--exec "${basedir}"/sbin/mysqld \
+		--pidfile "${pidfile}" \
+		--background \
+		--wait ${startup_early_timeout} \
+		${tmpnice} \
+		${tmpionice} \
+		-- --defaults-file="${MY_CNF}" ${MY_ARGS}
+	local ret=$?
+	if [ ${ret} -ne 0 ] ; then
+		eend ${ret}
+		return ${ret}
+	fi
+
+	ewaitfile ${startup_timeout} "${socket}"
+	eend $? || return 1
+
+	save_options pidfile "${pidfile}"
+	save_options basedir "${basedir}"
+}
+
+stop() {
+	ebegin "Stopping $(mysql_svcname)"
+
+	local pidfile="$(get_options pidfile)"
+	local basedir="$(get_options basedir)"
+	local stop_timeout=${STOP_TIMEOUT:-120}
+
+	start-stop-daemon \
+		${DEBUG/*/"--verbose"} \
+		--stop \
+		--exec "${basedir}"/sbin/mysqld \
+		--pidfile "${pidfile}" \
+		--retry ${stop_timeout}
+	eend $?
+}
+# vim: filetype=gentoo-init-d sw=2 ts=2 sts=2 noet:
+
diff --git a/dev-db/mysql-init-scripts/files/mysql-5.1.67-init.d b/dev-db/mysql-init-scripts/files/mysql-5.1.67-init.d
new file mode 100644
index 0000000..511a6bf
--- /dev/null
+++ b/dev-db/mysql-init-scripts/files/mysql-5.1.67-init.d
@@ -0,0 +1,118 @@
+#!/sbin/runscript
+# Copyright 1999-2013 Gentoo Foundation
+# Distributed under the terms of the GNU General Public License v2
+# $Header: /var/cvsroot/gentoo-x86/dev-db/mysql-init-scripts/files/mysql-5.1.67-init.d,v 1.1 2013/01/18 01:51:47 robbat2 Exp $
+
+depend() {
+	use net.lo
+	# localmount needed for $basedir
+	need localmount
+}
+
+get_config() {
+	my_print_defaults --config-file="$1" mysqld |
+	sed -n -e "s/^--$2=//p"
+}
+
+mysql_svcname() {
+	local ebextra=
+	case "${SVCNAME}" in
+		mysql*) ;;
+		*) ebextra=" (mysql)" ;;
+	esac
+	echo "${SVCNAME}${ebextra}"
+}
+
+start() {
+	# Check for old conf.d variables that mean migration was not yet done.
+	set | egrep -sq '^(mysql_slot_|MYSQL_BLOG_PID_FILE|STOPTIMEOUT)'
+	rc=$?
+	# Yes, MYSQL_INIT_I_KNOW_WHAT_I_AM_DOING is a hidden variable.
+	# It does have a use in testing, as it is possible to build a config file
+	# that works with both the old and new init scripts simulateously.
+	if [ "${rc}" = 0 -a -z "${MYSQL_INIT_I_KNOW_WHAT_I_AM_DOING}" ]; then
+		eerror "You have not updated your conf.d for the new mysql-init-scripts-2 revamp."
+		eerror "Not proceeding because it may be dangerous."
+		return 1
+	fi
+
+	# Now we can startup
+	ebegin "Starting $(mysql_svcname)"
+
+	MY_CNF="${MY_CNF:-/etc/${SVCNAME}/my.cnf}"
+
+	if [ ! -r "${MY_CNF}" ] ; then
+		eerror "Cannot read the configuration file \`${MY_CNF}'"
+		return 1
+	fi
+
+	# tail -n1 is critical as these we only want the last instance of the option
+	local basedir=$(get_config "${MY_CNF}" basedir | tail -n1)
+	local datadir=$(get_config "${MY_CNF}" datadir | tail -n1)
+	local pidfile=$(get_config "${MY_CNF}" pid-file | tail -n1)
+	local socket=$(get_config "${MY_CNF}" socket | tail -n1)
+
+	if [ ! -d "${datadir}" ] ; then
+		eerror "MySQL datadir \`${datadir}' is empty or invalid"
+		eerror "Please check your config file \`${MY_CNF}'"
+		return 1
+	fi
+
+	if [ ! -d "${datadir}"/mysql ] ; then
+		eerror "You don't appear to have the mysql database installed yet."
+		eerror "Please run /usr/bin/mysql_install_db to have this done..."
+		return 1
+	fi
+
+	local piddir="${pidfile%/*}"
+	checkpath -d --owner mysql:mysql --mode 0755 "$piddir"
+	rc=$?
+	if [ $rc -ne 0 ]; then
+		eerror "Directory $piddir for pidfile does not exist and cannot be created"
+		return 1
+	fi
+
+	local startup_timeout=${STARTUP_TIMEOUT:-900}
+	local startup_early_timeout=${STARTUP_EARLY_TIMEOUT:-1000}
+	local tmpnice="${NICE:+"--nicelevel "}${NICE}"
+	local tmpionice="${IONICE:+"--ionice "}${IONICE}"
+	start-stop-daemon \
+		${DEBUG:+"--verbose"} \
+		--start \
+		--exec "${basedir}"/sbin/mysqld \
+		--pidfile "${pidfile}" \
+		--background \
+		--wait ${startup_early_timeout} \
+		${tmpnice} \
+		${tmpionice} \
+		-- --defaults-file="${MY_CNF}" ${MY_ARGS}
+	local ret=$?
+	if [ ${ret} -ne 0 ] ; then
+		eend ${ret}
+		return ${ret}
+	fi
+
+	ewaitfile ${startup_timeout} "${socket}"
+	eend $? || return 1
+
+	save_options pidfile "${pidfile}"
+	save_options basedir "${basedir}"
+}
+
+stop() {
+	ebegin "Stopping $(mysql_svcname)"
+
+	local pidfile="$(get_options pidfile)"
+	local basedir="$(get_options basedir)"
+	local stop_timeout=${STOP_TIMEOUT:-120}
+
+	start-stop-daemon \
+		${DEBUG:+"--verbose"} \
+		--stop \
+		--exec "${basedir}"/sbin/mysqld \
+		--pidfile "${pidfile}" \
+		--retry ${stop_timeout}
+	eend $?
+}
+# vim: filetype=gentoo-init-d sw=2 ts=2 sts=2 noet:
+
diff --git a/dev-db/mysql-init-scripts/files/mysql.conf b/dev-db/mysql-init-scripts/files/mysql.conf
new file mode 100644
index 0000000..74cd5f8
--- /dev/null
+++ b/dev-db/mysql-init-scripts/files/mysql.conf
@@ -0,0 +1 @@
+d /var/run/mysqld 0755 mysql mysql -
diff --git a/dev-db/mysql-init-scripts/files/mysql.conf.d b/dev-db/mysql-init-scripts/files/mysql.conf.d
new file mode 100644
index 0000000..15ff170
--- /dev/null
+++ b/dev-db/mysql-init-scripts/files/mysql.conf.d
@@ -0,0 +1,80 @@
+#  Here is where we define which server(s) to start.
+#  Additional parameters to be passed to mysqld at startup may be added here,
+#  which will override the ones in "my.cnf".
+#
+#  Below are described some suggested parameters to use.
+#  The parameters not recognized will be passed through to the mysqld daemon
+#  directly!
+#  To avoid starting a server just comment it's definition.
+#
+#  Last but not least, SPACES are NOT allowed inside the parameters!
+#
+#  Parameter      : description
+# ----------------+-----------------------------------------------------------
+# nice            : integer [-20 .. 19 ] default 0
+#                 : change the priority of the server -20 (high) to 19 (low)
+#                 : see "man nice 1" for description
+# ----------------+-----------------------------------------------------------
+# mycnf           : string [full path to my.cnf]
+#                 : specify the path to my.cnf file to be used
+# ----------------+-----------------------------------------------------------
+# startup_timeout : integer [seconds] default 15
+#                 : time to wait for mysqld up and running, after this it's
+#                 : marked as failed
+# ----------------+-----------------------------------------------------------
+#
+#  Additional parameters
+#  Parameter      : description
+# ----------------+-----------------------------------------------------------
+# server-id       : integer [1 .. 255]
+#                 : Uniquely identifies the server instance in the community
+#                 : of replication partners.
+# ----------------+-----------------------------------------------------------
+# port            : integer [1025 .. 65535] default 3306
+#                 : Port number to use for connection.
+#                 : Looses any meaning if skip-networking is set.
+# ----------------+-----------------------------------------------------------
+# skip-networking : NULL
+#                 : Don't allow connection through TCP/IP.
+# ----------------+-----------------------------------------------------------
+# log-bin         : string [name of the binlog files]
+#                 : Log update queries in binary format. Optional (but
+#                 : strongly recommended to avoid replication problems if
+#                 : server's hostname changes) argument should be the chosen
+#                 : location for the binary log files.
+# ----------------+-----------------------------------------------------------
+# Additionally the following variables are recognized:
+#
+# Be more verbose, accepts values from 1 to 4
+#DEBUG=4
+#
+# The default location for the "master" pid file
+#MYSQL_GLOB_PID_FILE="/var/run/svc-started-mysqld"
+#
+# The timeout for a failed attempt to stop a server
+#STOPTIMEOUT=120
+#
+
+# The parameters are passed in a bash array variable,
+# the variable name is mysql_slot_0_[server-num]
+# "server-num" is an optional number used to start multiple servers
+#
+# Examples:
+#
+# start a default server with default options:
+#mysql_slot_0=()
+#
+# start MySQL reniced, overriding some start parameters
+#mysql_slot_0=(
+#   "nice=-5"
+#   "server-id=123"
+#   "log-bin="myhost"
+#   "port=3307"
+#)
+#
+# start another server, different my.cnf
+#mysql_slot_0_1=(
+#   "mycnf=/home/test/my.cnf"
+#   "server-id=124"
+#)
+#
diff --git a/dev-db/mysql-init-scripts/files/mysql.rc6 b/dev-db/mysql-init-scripts/files/mysql.rc6
new file mode 100644
index 0000000..e67c2ca
--- /dev/null
+++ b/dev-db/mysql-init-scripts/files/mysql.rc6
@@ -0,0 +1,358 @@
+#!/sbin/runscript
+# Copyright 1999-2006 Gentoo Foundation
+# Distributed under the terms of the GNU General Public License v2
+# $Header: /var/cvsroot/gentoo-x86/dev-db/mysql-init-scripts/files/mysql.rc6,v 1.2 2007/03/04 15:47:03 vivo Exp $
+
+# external binaries used: which, sed, tac
+
+# int in_list(char * elem, char * list)
+function in_list() {
+	local elem=${1:-"none"}
+	local list=${2:-","}
+
+	[[ "${list}" == "${list/,${elem},/}" ]] \
+	&& return 1 \
+	|| return 0
+}
+
+function wdebug() {
+	if [[ "${DEBUG}" -ge "${1}" ]] ; then
+		shift
+		echo "dbg:  ${@}"
+	fi
+}
+
+depend() {
+	use dns net localmount netmount nfsmount
+}
+
+do_escape() {
+	# Ihatethisreallyverymuch
+	#echo "$1" | sed -e "s|'| |" -e "s|=|='|" -e "s|$|'|"
+	echo "$1"
+}
+
+# int get_slot_config(srv_slot=0, srv_num)
+get_slot_config() {
+	wdebug 4 ">>> get_slot_config()"
+
+	local srv srv_slot srv_num
+	srv_slot="${1:-"0"}"
+	srv_num="${2}"
+	MY_SUFFIX="-${srv_slot}"
+	# srv=array(0 => [srv_slot], 1 => [srv_num] )
+	srv=( ${srv_slot} ${srv_num} )
+
+	local tmp_eval="mysql_slot_${srv_slot}${srv_num:+"_"}${srv_num}[@]"
+	local conf_d_parameters="${!tmp_eval}"
+	if [[ "${srv_slot}" == "0" ]] ; then
+		MY_SUFFIX=''
+		# try some other default for the default server
+		[[ -z "${conf_d_parameters[@]}" ]] && conf_d_parameters=${mysql_slot[@]}
+	fi
+	[[ -z "${conf_d_parameters[@]}" ]] && conf_d_parameters=( )
+	basedir="" datadir="" pidfile="" socket=""
+	CHROOT="" NICE="" STARTUPTIMEOUT=5 STOPTIMEOUT=120
+
+	wdebug 3 "srv                ${srv[@]}"
+	wdebug 3 "srv_slot           ${srv_slot}"
+	wdebug 3 "srv_num            ${srv_num}"
+	wdebug 3 "tmp_eval           ${tmp_eval}"
+	wdebug 3 "conf_d_parameters  ${conf_d_parameters[@]}"
+	wdebug 3 "MY_SUFFIX          ${MY_SUFFIX}"
+
+	local tmp_eval="mysql_slot_${srv_slot}${srv_num:+"_"}${srv_num}[@]"
+	local conf_d_parameters="${!tmp_eval}"
+	# collations need to be defined *after* the character sets,
+	# so we will duplicate them
+	local collations=""
+	[[ ${conf_d_parameters[*]} == '()' ]] && conf_d_parameters=''
+
+	MY_CNF="/etc/mysql${MY_SUFFIX}/my.cnf"
+	# summa of unmanaged parameters
+	# some parameters may be present multiple times
+	unmanagedparams=""
+
+	# grab the parameters from conf.d/mysql definition
+	for my_default in ${conf_d_parameters[*]} ; do
+		case "${my_default}" in
+			nice=*)
+				NICE="${my_default#nice=}"
+				nice -n $NICE ls /tmp &>/dev/null || NICE=""
+				;;
+			mycnf=*) MY_CNF="${my_default#mycnf=}" ;;
+			startup_timeout=*)
+				STARTUPTIMEOUT="${my_default#startup_timeout=}"	;;
+			basedir=*) basedir="${my_default#basedir=}" ;;
+			datadir=*) datadir="${my_default#datadir=}" ;;
+			pid-file=*) pidfile="${my_default#pid-file=}" ;;
+			socket=*) socket="${my_default#socket=}" ;;
+			*collation*=)
+				collations="${collations} --$( do_escape "${my_default}" )"
+				;;
+			*=*)
+				# list of parameters we already have
+				# prepend "--" because my_print_defaults do it
+				unmanagedparams="${unmanagedparams} --$( do_escape "${my_default}" )"
+				;;
+			*)
+				unmanagedparams="${unmanagedparams} --${my_default}"
+				;;
+		esac
+	done
+
+	if [[ ! -r "${MY_CNF}" ]] ; then
+		ewarn "Cannot access ${MY_CNF} !"
+		MY_CNF=""
+		my_defaults=""
+	else
+		local my_print_defaults="$(which my_print_defaults${MY_SUFFIX} 2>/dev/null)"
+		if [[ ! -x "${my_print_defaults}" ]] ; then
+			eerror "my_print_defaults NOT found or not executable"
+			my_defaults=""
+		else
+			my_defaults=$( ${my_print_defaults} \
+			--loose-verbose \
+			--config-file="${MY_CNF}" \
+			mysqld server )
+		fi
+	fi
+
+	# grab needed parameters from my.cnf, don't override the ones from
+	# conf.d/mysql
+	for my_default in ${my_defaults} ; do
+		case "${my_default}" in
+			--basedir=*)
+				[[ -z "${basedir}" ]] && basedir="${my_default#--basedir=}" ;;
+			--datadir=*)
+				[[ -z "${datadir}" ]] && datadir="${my_default#--datadir=}" ;;
+			--pid-file=*)
+				[[ -z "${pidfile}" ]] && pidfile="${my_default#--pid-file=}" ;;
+			--socket=*)
+				[[ -z "${socket}" ]] && socket="${my_default#--socket=}" ;;
+			--*collation*=)
+				# the order is inversed because we want the conf.d ones overriden
+				collations="$( do_escape "${my_default}" ) ${collations}"
+				;;
+		esac
+	done
+
+	# some parameters
+	basedir="${basedir:-"/usr"}"
+	datadir="${datadir:-"/var/lib/mysql${MY_SUFFIX}"}"
+	pidfile="${pidfile:-"/var/run/mysqld/mysqld${MY_SUFFIX}.pid"}"
+	socket="${socket:-"/var/run/mysqld/mysqld${MY_SUFFIX}.sock"}"
+	unmanagedparams="${unmanagedparams} ${collations}"
+
+	wdebug 3 "chroot dir => ${CHROOT}"
+	wdebug 3 "niceness   => ${NICE}"
+	wdebug 3 "basedir    => ${basedir}"
+	wdebug 3 "datadir    => ${datadir}"
+	wdebug 3 "pidfile    => ${pidfile}"
+	wdebug 3 "socket     => ${socket}"
+	wdebug 3 "Unamanged  => ${unmanagedparams}"
+
+	# extension for sleep tenth of seconds, not very portable so check it before
+	if sleep 0.01 ; then
+		STARTUPTIMEOUT=$(( STARTUPTIMEOUT * 10 ))
+		STOPTIMEOUT=$(( STOPTIMEOUT * 10 ))
+		TIMEUNIT=0.1
+	else
+		TIMEUNIT=1
+	fi
+
+	# push these out to the script
+	export MY_SUFFIX NICE MY_CNF pidfile datadir basedir socket CHROOT
+	export unmanagedparams STARTUPTIMEOUT STOPTIMEOUT TIMEUNIT
+	wdebug 4 "<<< get_slot_config() ok"
+	return 0
+}
+
+checkconfig() {
+	wdebug 4 ">>> checkconfig(\"${1}\")"
+	local datadir="${1}" pidfile="${2}" socket="${3}"
+
+	if [[ -n "${NOCHECK}" ]] ; then
+		rm -f "${pidfile}" "${socket}"
+		return 0
+	fi
+
+	if [[ ! -d "${datadir}" ]] ; then
+		eerror "MySQL datadir is empty or invalid"
+		eerror "Please check your my.cnf : ${MY_CNF}"
+		wdebug 4 "<<< checkconfig() KO"
+		return 1
+	fi
+
+	if [[ ! -d "${datadir}/mysql" ]] ; then
+		eerror "You don't appear to have the mysql database installed yet."
+		eerror "Please run /usr/bin/mysql_install_db to have this done..."
+		wdebug 4 "<<< checkconfig() KO"
+		return 1
+	fi
+
+	if [[ -f "${pidfile}" ]] ; then
+		kill -15 $(< ${pidfile}) 2>/dev/null
+		if [[ $? -eq 0 ]] ; then
+			# the process exist, we have a problem
+			eerror "\"${pidfile}\" is still present and the process is running."
+			eerror "Please stop it \"kill $(< ${pidfile})\" maybe ?"
+			wdebug 4 "<<< checkconfig() KO"
+			return 1
+		else
+			rm -f "${pidfile}"
+		fi
+	fi
+
+	if [[ -S "${socket}" ]] ; then
+		ewarn "Strange, the socket file already exist in \"${socket}\""
+		ewarn "it will be removed now and re-created by the MySQL server"
+		ewarn "BUT please make your checks."
+		rm -f "${socket}"
+	fi
+
+	wdebug 4 "<<< checkconfig() ok"
+	return 0
+}
+
+start() {
+	wdebug 4 ">>> start()"
+
+	MYSQL_GLOB_PID_FILE=${MYSQL_GLOB_PID_FILE:-"/var/run/svc-started-${SVCNAME/mysql/mysqld}"}
+	# servers are defined in /etc/conf.d/mysql
+	local serverlist=${!mysql_slot_*}
+	# provide default for empty conf.d/mysql
+	if [[ -z "${serverlist}" ]] ; then
+		serverlist=0
+		export mysql_slot_0=( )
+	fi
+	local retstatus timeout
+	local globretstatus=1
+	local srv_slot srv_num
+	# server MUST NOT share same location for these
+	local pidfilelist=',' datadirlist=',' socketlist=','
+	local ssd_thing=1
+	local mysqld_thing tmpnice
+
+	ebegin "Starting ${myservice}"
+	# try to start each server
+	for srv in ${serverlist[*]} ; do
+
+		srv_slot="${srv#mysql_slot_}"
+		if [[ "${srv_slot}" == "${srv_slot#*_}" ]] ; then
+			srv_num=''
+		else
+			srv_num="${srv_slot#*_}"
+		fi
+		srv_slot="${srv_slot%%_*}"
+
+		retstatus=0
+		get_slot_config "${srv_slot}" "${srv_num}" || retstatus=1
+
+		# checks
+		if ! checkconfig "${datadir}" "${pidfile}" "${socket}" ; then
+			retstatus=2 ; continue
+		fi
+		if in_list "${pidfile}" "${pidfilelist}" ; then
+			eerror "Sorry, won't start with same pid-file: ${pidfile}"
+			retstatus=3 ; continue
+		fi
+		if in_list "${datadir}" "${datadirlist}" ; then
+			eerror "Sorry, won't start with same datadir: ${datadir}"
+			retstatus=4 ; continue
+		fi
+		if in_list "${socket}" "${socketlist}" ; then
+			eerror "Sorry, won't start with same socket: ${socket}"
+			retstatus=5 ; continue
+		fi
+
+		einfo "Starting ${myservice} (${MY_CNF})"
+
+		mysqld_thing="${MY_CNF:+"--defaults-file="}${MY_CNF}"
+		mysqld_thing="${mysqld_thing} ${unmanagedparams}"
+		mysqld_thing="${mysqld_thing} --basedir=${basedir}"
+		mysqld_thing="${mysqld_thing} --datadir=${datadir}"
+		mysqld_thing="${mysqld_thing} --pid-file=${pidfile}"
+		mysqld_thing="${mysqld_thing} --socket=${socket}"
+
+		wdebug 2 "starting mysqld with: ${mysqld_thing}"
+
+		if [[ ${ssd_thing} -eq 1 ]] ; then
+			tmpnice="${NICE:+"--nicelevel "}${NICE}"
+			start-stop-daemon --quiet ${DEBUG/*/"--verbose"} --start \
+			--background ${tmpnice} --pidfile ${pidfile} \
+			--exec ${basedir}/sbin/mysqld${MY_SUFFIX} -- ${mysqld_thing} \
+			&& sleep ${TIMEUNIT}
+			retstatus=$?
+		else
+			tmpnice="${NICE:+"nice -n "}${NICE}"
+			${tmpnice} ${basedir}/sbin/mysqld${MY_SUFFIX} ${mysqld_thing} &
+			retstatus=0
+		fi
+
+		# only the first run is done by start-stop-daemon
+		ssd_thing=""
+
+		# wait for socket creation
+		wdebug 1
+		while ! [[ -S "${socket}" || "${STARTUPTIMEOUT}" -lt 1 || "${retstatus}" -ne 0 ]] ; do
+			STARTUPTIMEOUT=$(( STARTUPTIMEOUT - 1 ))
+			[[ ${DEBUG} -ge 1 ]] && echo -n "${STARTUPTIMEOUT},"
+			sleep ${TIMEUNIT}
+		done
+		wdebug 1 ""
+		if [[ ! -S "${socket}" ]] ; then
+			eerror "MySQL${MY_SUFFIX} NOT started (${retstatus})"
+			retstatus=1
+		else
+			globretstatus=0
+			pidfilelist="${pidfilelist}${pidfile},"
+			datadirlist="${datadirlist}${datadir},"
+			socketlist="${socketlist}${socket},"
+			echo "${srv_slot}${srv_num:+"_"}${srv_num}=${pidfile}" >> "${MYSQL_GLOB_PID_FILE}"
+		fi
+	done
+	# successfull if at least one mysqld started
+	wdebug 4 "<<< start()"
+	eend $globretstatus
+}
+
+stop() {
+	get_slot_config &> /dev/null
+	MYSQL_GLOB_PID_FILE=${MYSQL_GLOB_PID_FILE:-"/var/run/svc-started-${SVCNAME/mysql/mysqld}"}
+	local runwhat pidfile shutdown_elem
+	local PID cnt timeout=${STOPTIMEOUT:-"120"}
+	local retstatus=0
+	local shutdown_list="$(< "${MYSQL_GLOB_PID_FILE}" )"
+
+	ebegin "Stopping ${myservice}"
+	wdebug 5 "MYSQL_GLOB_PID_FILE: ${MYSQL_GLOB_PID_FILE}"
+	wdebug 5 "shutdown_list: ${shutdown_list}"
+	for shutdown_elem in ${shutdown_list} ; do
+		runwhat=${shutdown_elem%%=*}
+		pidfile=${shutdown_elem#*=}
+		timeout=${STOPTIMEOUT:-"120"}
+		PID=$(< "${pidfile}" )
+		wdebug 3 "runwhat            ${runwhat}"
+		wdebug 3 "pidfile            ${pidfile}"
+		wdebug 3 "timeout            ${timeout}"
+		wdebug 3 "PID                ${PID}"
+
+		einfo "Stopping mysqld (${runwhat})"
+
+		start-stop-daemon --quiet ${DEBUG/*/"--verbose"} --stop --pidfile "${pidfile}" &
+		wdebug 1 ""
+		while [[ -n "$PID" ]] \
+			&& $( ps -Ao pid | grep -q "^ *$PID$" ) \
+			&& [[ "${timeout}" -ge 1 ]]
+		do
+			timeout=$(($timeout - 1))
+			[[ ${DEBUG} -ge 1 ]] && echo -n "$(( $STOPTIMEOUT - $timeout )),"
+			sleep ${TIMEUNIT}
+		done
+		[[ "${timeout}" -lt 1 ]] && retstatus=1
+	done
+	sleep ${TIMEUNIT}
+	[[ "$retstatus" -eq 0 ]] && rm -f "$MYSQL_GLOB_PID_FILE"
+	eend ${retstatus}
+}
diff --git a/dev-db/mysql-init-scripts/files/mysqld-wait-ready b/dev-db/mysql-init-scripts/files/mysqld-wait-ready
new file mode 100644
index 0000000..9e5d3e4
--- /dev/null
+++ b/dev-db/mysql-init-scripts/files/mysqld-wait-ready
@@ -0,0 +1,56 @@
+#!/bin/sh
+
+# This script waits for mysqld to be ready to accept connections
+# (which can be many seconds or even minutes after launch, if there's
+# a lot of crash-recovery work to do).
+# Running this as ExecStartPost is useful so that services declared as
+# "After mysqld" won't be started until the database is really ready.
+
+# Service file passes us the daemon's PID (actually, mysqld_safe's PID)
+daemon_pid="$1"
+
+# extract value of a MySQL option from config files
+# Usage: get_mysql_option SECTION VARNAME DEFAULT
+# result is returned in $result
+# We use my_print_defaults which prints all options from multiple files,
+# with the more specific ones later; hence take the last match.
+get_mysql_option(){
+	result=`/usr/bin/my_print_defaults "$1" | sed -n "s/^--$2=//p" | tail -n 1`
+	if [ -z "$result" ]; then
+	    # not found, use default
+	    result="$3"
+	fi
+}
+
+# Defaults here had better match what mysqld_safe will default to
+get_mysql_option mysqld datadir "/var/lib/mysql"
+datadir="$result"
+get_mysql_option mysqld socket "/var/lib/mysql/mysql.sock"
+socketfile="$result"
+
+# Wait for the server to come up or for the mysqld process to disappear
+ret=0
+while /bin/true; do
+	RESPONSE=`/usr/bin/mysqladmin --no-defaults --socket="$socketfile" --user=UNKNOWN_MYSQL_USER ping 2>&1`
+	mret=$?
+	if [ $mret -eq 0 ]; then
+	    break
+	fi
+	# exit codes 1, 11 (EXIT_CANNOT_CONNECT_TO_SERVICE) are expected,
+	# anything else suggests a configuration error
+	if [ $mret -ne 1 -a $mret -ne 11 ]; then
+	    ret=1
+	    break
+	fi
+	# "Access denied" also means the server is alive
+	echo "$RESPONSE" | grep -q "Access denied for user" && break
+
+	# Check process still exists
+	if ! /bin/kill -0 $daemon_pid 2>/dev/null; then
+	    ret=1
+	    break
+	fi
+	sleep 1
+done
+
+exit $ret
diff --git a/dev-db/mysql-init-scripts/files/mysqld.service b/dev-db/mysql-init-scripts/files/mysqld.service
new file mode 100644
index 0000000..de9ea2f
--- /dev/null
+++ b/dev-db/mysql-init-scripts/files/mysqld.service
@@ -0,0 +1,26 @@
+[Unit]
+Description=MySQL database server
+After=syslog.target
+After=network.target
+
+[Service]
+Type=simple
+User=mysql
+Group=mysql
+
+# Note: we set --basedir to prevent probes that might trigger SELinux alarms,
+# https://bugzilla.redhat.com/show_bug.cgi?id=547485
+ExecStart=/usr/bin/mysqld_safe --basedir=/usr
+ExecStartPost=/usr/libexec/mysqld-wait-ready $MAINPID
+
+# Give a reasonable amount of time for the server to start up/shut down
+TimeoutSec=300
+
+# We rely on systemd, not mysqld_safe, to restart mysqld if it dies
+Restart=always
+
+# Place temp files in a secure directory, not /tmp
+PrivateTmp=true
+
+[Install]
+WantedBy=multi-user.target
diff --git a/dev-db/mysql-init-scripts/files/mysqld_at.service b/dev-db/mysql-init-scripts/files/mysqld_at.service
new file mode 100644
index 0000000..f46cf9e
--- /dev/null
+++ b/dev-db/mysql-init-scripts/files/mysqld_at.service
@@ -0,0 +1,26 @@
+[Unit]
+Description=MySQL database server
+ConditionPathExists=/etc/mysql/my%I.cnf
+After=network.target
+
+[Service]
+Type=simple
+User=mysql
+Group=mysql
+
+# Note: we set --basedir to prevent probes that might trigger SELinux alarms,
+# https://bugzilla.redhat.com/show_bug.cgi?id=547485
+ExecStart=/usr/bin/mysqld_safe --defaults-file=/etc/mysql/my%I.cnf --basedir=/usr
+ExecStartPost=/usr/libexec/mysqld-wait-ready $MAINPID
+
+# Give a reasonable amount of time for the server to start up/shut down
+TimeoutSec=300
+
+# We rely on systemd, not mysqld_safe, to restart mysqld if it dies
+Restart=always
+
+# Place temp files in a secure directory, not /tmp
+PrivateTmp=true
+
+[Install]
+WantedBy=multi-user.target
diff --git a/dev-db/mysql-init-scripts/files/mysqlmanager.conf.d b/dev-db/mysql-init-scripts/files/mysqlmanager.conf.d
new file mode 100644
index 0000000..8666f71
--- /dev/null
+++ b/dev-db/mysql-init-scripts/files/mysqlmanager.conf.d
@@ -0,0 +1,28 @@
+#  Here is where we define which server(s) to start.
+#  Additional parameters to be passed to mysqlmanager at startup may be added here,
+#  which will override the ones in "my.cnf".
+#
+#  To avoid starting a server just comment it's definition
+#  here or it will rant (no default start).
+#  Last but not least, spaces are NOT allowed inside the parameters!
+#
+#  Below are described some suggested parameters to use.
+#  The parameters not recognized will be passed through to the mysqlmanager directly.
+#
+#  Parameter      : description
+
+# ----------------+-----------------------------------------------------------
+# mycnf           : string [full path to my.cnf]
+#                 : specify the path to my.cnf file to be used
+#                 : may contain a [manager] section
+# ----------------+-----------------------------------------------------------
+#
+# Basic default
+#
+#mysqlmanager_slot_0=()
+#
+# Start MySQL 5.0.X overriding the my.cnf path
+#mysqlmanager_slot_500=(
+#	"mycnf=/home/test/my.cnf"
+#)
+#
diff --git a/dev-db/mysql-init-scripts/files/mysqlmanager.rc6 b/dev-db/mysql-init-scripts/files/mysqlmanager.rc6
new file mode 100644
index 0000000..dd8b703
--- /dev/null
+++ b/dev-db/mysql-init-scripts/files/mysqlmanager.rc6
@@ -0,0 +1,230 @@
+#!/sbin/runscript
+# Copyright 1999-2006 Gentoo Foundation
+# Distributed under the terms of the GNU General Public License v2
+# $Header: /var/cvsroot/gentoo-x86/dev-db/mysql-init-scripts/files/mysqlmanager.rc6,v 1.1 2007/01/12 16:54:20 chtekk Exp $
+
+# external binaries used: which, sed, tac
+
+depend() {
+	use dns net localmount netmount nfsmount
+	#provide mysql
+}
+
+# int in_list(char * elem, char * list)
+function in_list() {
+	local elem=${1:-"none"}
+	local list=${2:-","}
+
+	[[ "${list}" == "${list/,${elem},/}" ]] \
+	&& return 1 \
+	|| return 0
+}
+
+do_escape() {
+	# Ihatethisreallyverymuch
+	#echo "$1" | sed -e "s|'| |" -e "s|=|='|" -e "s|$|'|"
+	echo "$1"
+}
+
+# int get_slot_config(srv_slot=0, srv_num)
+get_slot_config() {
+	[[ ${DEBUG} -ge 4 ]] && einfo ">>> get_slot_config(\"${1}\", \"${2}\")"
+
+	srv_slot="${1:-"0"}"
+	srv_num="${2}"
+	MY_SUFFIX="-${srv_slot}"
+	[[ "${MY_SUFFIX}" == '-0' ]] && MY_SUFFIX=''
+
+	basedir="" pidfile="" socket=""
+
+	local tmp_eval="mysqlmanager_slot_${srv_slot}${srv_num:+"_"}${srv_num}[@]"
+	local conf_d_parameters="${!tmp_eval}"
+	[[ ${conf_d_parameters[*]} == '()' ]] && conf_d_parameters=''
+
+	MY_CNF="/etc/mysql${MY_SUFFIX}/my.cnf"
+	# summa of unmanaged parameters
+	# some parameters may be present multiple times
+	unmanagedparams=""
+
+	# grab the parameters from conf.d/mysql definition
+	for my_default in ${conf_d_parameters[*]} ; do
+		case "${my_default}" in
+			mycnf=*) MY_CNF="${my_default#mycnf=}" ;;
+			basedir=*) basedir="${my_default#basedir=}" ;;
+			pid-file=*) pidfile="${my_default#pid-file=}" ;;
+			socket=*) socket="${my_default#socket=}" ;;
+			*=*)
+				# list of parameters we already have
+				# prepend "--" because my_print_defaults do it
+				unmanagedparams="${unmanagedparams} --$( do_escape "${my_default}" )"
+				;;
+			*)
+				unmanagedparams="${unmanagedparams} --${my_default}"
+				;;
+		esac
+	done
+
+	if [[ ! -r "${MY_CNF}" ]] ; then
+		ewarn "Cannot access ${MY_CNF} !"
+		MY_CNF=""
+		my_defaults=""
+	else
+		local my_print_defaults="$(which my_print_defaults${MY_SUFFIX} 2>/dev/null)"
+		if [[ ! -x "${my_print_defaults}" ]] ; then
+			eerror "my_print_defaults NOT found or not executable"
+			my_defaults=""
+		else
+			my_defaults=$( ${my_print_defaults} \
+			--loose-verbose \
+			--config-file="${MY_CNF}" \
+			manager )
+		fi
+	fi
+
+	# grab needed parameters from my.cnf, don't override the ones from
+	# conf.d/mysql
+	for my_default in ${my_defaults} ; do
+		case "${my_default}" in
+			--pid-file=*)
+				[[ -z "${pidfile}" ]] && pidfile="${my_default#--pid-file=}" ;;
+			--socket=*)
+				[[ -z "${socket}" ]] && socket="${my_default#--socket=}" ;;
+		esac
+	done
+
+	# still empty, I'm in doubt if assign a default or break, will see
+	basedir="${basedir:-"/usr"}"
+	pidfile="${pidfile:-"/var/run/mysqld/mysqlmanager${MY_SUFFIX}.pid"}"
+	socket="${socket:-"/var/run/mysqld/mysqlmanager${MY_SUFFIX}.sock"}"
+
+	if [[ ${DEBUG} -ge 3 ]] ; then
+		einfo "basedir    => ${basedir}"
+		einfo "pidfile    => ${pidfile}"
+		einfo "socket     => ${socket}"
+		einfo "Unamanged  => ${unmanagedparams}"
+	fi
+
+	# push these out to the script
+	export MY_SUFFIX MY_CNF pidfile basedir socket
+	export unmanagedparams
+	[[ ${DEBUG} -ge 4 ]] && einfo "<<< get_slot_config() ok"
+	return 0
+}
+
+start() {
+	[[ ${DEBUG} -ge 4 ]] && einfo ">>> start()"
+	MYSQL_GLOB_PID_FILE=${MYSQL_GLOB_PID_FILE:-"/var/run/svc-started-${SVCNAME}"}
+	# servers are defined in /etc/conf.d/mysql
+	local serverlist=${!mysqlmanager_slot_*}
+	# provide default for empty conf.d/mysql
+	if [[ -z "${serverlist}" ]] ; then
+		serverlist=0
+		export mysqlmanager_slot_0=()
+	fi
+	local retstatus timeout
+	local globretstatus=1
+	local srv_slot srv_num
+	# server MUST NOT share same location for these
+	local pidfilelist=',' socketlist=','
+
+	# additional security
+	rm -f "${MYSQL_GLOB_PID_FILE}" ; touch "${MYSQL_GLOB_PID_FILE}"
+	if [[ $? -ne 0 ]] ; then
+		eerror "cannot create MYSQL_GLOB_PID_FILE: ${MYSQL_GLOB_PID_FILE}"
+		[[ ${DEBUG} -ge 4 ]] && einfo "<<< start() KO"
+		return 1
+	fi
+
+	ebegin
+	# try to start each server
+	for srv in ${serverlist[*]} ; do
+		einfo "working on ${srv}"
+
+		srv_slot="${srv#mysqlmanager_slot_}"
+		if [[ "${srv_slot}" == "${srv_slot#*_}" ]] ; then
+			srv_num=''
+		else
+			srv_num="${srv_slot#*_}"
+		fi
+		srv_slot="${srv_slot%%_*}"
+
+		retstatus=0
+		get_slot_config "${srv_slot}" "${srv_num}" || retstatus=1
+
+		# timeout (seconds) before declaring the startup failed
+
+		# pre_run checks
+		if [[ "$retstatus" -eq 0 ]] ; then
+			if in_list "${pidfile}" "${pidfilelist}" ; then
+				retstatus=3
+				eerror "Sorry, won't start with same pid-file: ${pidfile}"
+			fi
+			if in_list "${socket}" "${socketlist}" ; then
+				retstatus=5
+				eerror "Sorry, won't start with same socket: ${socket}"
+			fi
+		fi
+
+		if [[ $retstatus -eq 0 ]] ; then
+			# additional security
+			rm -f ${pidfile} ${socket}
+			einfo "Starting mysqlmanager${MY_SUFFIX:+"_"}${srv_slot}${srv_num:+"_"}${srv_num} (${MY_CNF})"
+
+			[[ ${DEBUG} -ge 2 ]] && echo "starting mysqlmanager with: "${basedir}/sbin/mysqlmanager${MY_SUFFIX} ${unmanagedparams} --pid-file=${pidfile} --socket=${socket}
+
+			start-stop-daemon --quiet --start --background \
+				--pidfile "${pidfile}" \
+				--exec ${basedir}/sbin/mysqlmanager${MY_SUFFIX} \
+				-- \
+					${MY_CNF:+"--defaults-file="}${MY_CNF} \
+					${unmanagedparams} \
+					--pid-file=${pidfile} \
+					--socket=${socket}
+
+			retstatus=$?
+
+			if [[ "${retstatus}" -eq 0 ]] ; then
+				pidfilelist="${pidfilelist}${pidfile},"
+				socketlist="${socketlist}${socket},"
+				globretstatus=0
+				echo "${srv_slot}${srv_num:+"_"}${srv_num}=${pidfile}" >> "${MYSQL_GLOB_PID_FILE}"
+			fi
+		fi
+	done
+	# successfull if at least one mysqlmanager started
+	[[ ${DEBUG} -ge 4 ]] && einfo "<<< start()"
+	eend $globretstatus
+}
+
+stop () {
+	MYSQL_GLOB_PID_FILE=${MYSQL_GLOB_PID_FILE:-"/var/run/svc-started-${SVCNAME}"}
+	local runwhat pidfile shutdown_elem
+	local PID cnt timeout
+	local retstatus=0
+	local shutdown_list="$(< "${MYSQL_GLOB_PID_FILE}" )"
+
+	# shutdown in reverse order
+	ebegin
+	for shutdown_elem in $shutdown_list; do
+		runwhat=${shutdown_elem%%=*}
+		pidfile=${shutdown_elem#*=}
+		timeout=${STOPTIMEOUT:-"10"}
+
+		einfo "Stopping mysqlmanager (${runwhat})"
+
+		PID=$(cat "${pidfile}" 2>/dev/null)
+		start-stop-daemon --stop --quiet --pidfile="${pidfile}"
+		[[ ${DEBUG} -ge 1 ]] && echo ""
+		while [[ -n "$PID" && $( kill -0 $PID 2>/dev/null ) && "${timeout}" -ge 1 ]] ; do
+			timeout=$(($timeout - 1))
+			[[ ${DEBUG} -ge 1 ]] && echo -n $(( $STOPTIMEOUT - $timeout ))
+			sleep 1
+		done
+		if [[ "${timeout}" -lt 1 ]] ; then
+			retstatus=$(( $retstatus + 1 ))
+		fi
+	done
+
+	[[ "$retstatus" -eq 0 ]] && rm -f "$MYSQL_GLOB_PID_FILE"
+	eend $retstatus
+}
diff --git a/dev-db/mysql-init-scripts/metadata.xml b/dev-db/mysql-init-scripts/metadata.xml
new file mode 100644
index 0000000..abf3529
--- /dev/null
+++ b/dev-db/mysql-init-scripts/metadata.xml
@@ -0,0 +1,5 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!DOCTYPE pkgmetadata SYSTEM "http://www.gentoo.org/dtd/metadata.dtd">
+<pkgmetadata>
+	<herd>mysql</herd>
+</pkgmetadata>
diff --git a/dev-db/mysql-init-scripts/mysql-init-scripts-2.0_pre1-r6.ebuild b/dev-db/mysql-init-scripts/mysql-init-scripts-2.0_pre1-r6.ebuild
new file mode 100644
index 0000000..a8b3150
--- /dev/null
+++ b/dev-db/mysql-init-scripts/mysql-init-scripts-2.0_pre1-r6.ebuild
@@ -0,0 +1,64 @@
+# Copyright 1999-2014 Gentoo Foundation
+# Distributed under the terms of the GNU General Public License v2
+# $Header: /var/cvsroot/gentoo-x86/dev-db/mysql-init-scripts/mysql-init-scripts-2.0_pre1-r6.ebuild,v 1.9 2014/01/11 09:33:00 pacho Exp $
+
+inherit systemd
+
+DESCRIPTION="Gentoo MySQL init scripts."
+HOMEPAGE="http://www.gentoo.org/"
+SRC_URI=""
+
+LICENSE="GPL-2"
+SLOT="0"
+KEYWORDS="*"
+IUSE=""
+
+DEPEND=""
+# This _will_ break with MySQL 5.0, 4.x, 3.x
+# It also NEEDS openrc for the save_options/get_options builtins.
+RDEPEND="!<dev-db/mysql-5.1"
+
+src_install() {
+	newconfd "${FILESDIR}/mysql-5.1.53-conf.d" "mysql"
+	newinitd "${FILESDIR}/mysql-5.1.67-init.d" "mysql"
+
+	# systemd unit installation
+	exeinto /usr/libexec
+	doexe "${FILESDIR}"/mysqld-wait-ready
+	systemd_dounit "${FILESDIR}/mysqld.service"
+	systemd_newunit "${FILESDIR}/mysqld_at.service" "mysqld@.service"
+	systemd_dotmpfilesd "${FILESDIR}/mysql.conf"
+
+	insinto /etc/logrotate.d
+	newins "${FILESDIR}/logrotate.mysql" "mysql"
+}
+
+pkg_postinst() {
+	grep -sq mysql_slot "${ROOT}"/etc/conf.d/mysql
+	old_conf_present=$?
+	grep -sq get_slot_config "${ROOT}"/etc/init.d/mysql
+	old_init_present=$?
+
+	egrep -sq 'MY_CNF|MY_ARGS|(STARTUP|STOP)_TIMEOUT' "${ROOT}"/etc/conf.d/mysql
+	new_conf_present=$?
+	egrep -sq 'MY_ARGS|STOP_TIMEOUT' "${ROOT}"/etc/init.d/mysql
+	new_init_present=$?
+
+	einfo "Please note that if you are using multiple internal 'slots' in the"
+	einfo "old conf.d file, you should use multiple init files now."
+	echo old $old_conf_present $old_init_present
+	echo new $new_conf_present $new_init_present
+
+	# new scripts present
+	if [ $new_conf_present -eq 0 -a $new_init_present -eq 0 -a \
+		 $old_conf_present -eq 1 -a $old_init_present -eq 1 ]; then
+		:
+	elif [ $old_conf_present -eq 0 -a $old_init_present -eq 0 -a \
+		 $new_conf_present -eq 1 -a $new_init_present -eq 1 ]; then
+		ewarn "Old /etc/init.d/mysql and /etc/conf.d/mysql still present!"
+		ewarn "Update both of those files to the new versions!"
+	else
+		eerror "DANGER, mixed update of /etc/init.d/mysql and /etc/conf.d/mysql"
+		eerror "detected! You must update BOTH to the new versions"
+	fi
+}
diff --git a/eclass/mysql-autotools.eclass b/eclass/mysql-autotools.eclass
index f3aa85e..644c1e7 100644
--- a/eclass/mysql-autotools.eclass
+++ b/eclass/mysql-autotools.eclass
@@ -1,6 +1,6 @@
-# Copyright 1999-2012 Gentoo Foundation
+# Copyright 1999-2013 Gentoo Foundation
 # Distributed under the terms of the GNU General Public License v2
-# $Header: /var/cvsroot/gentoo-x86/eclass/mysql-autotools.eclass,v 1.10 2012/11/01 23:57:50 robbat2 Exp $
+# $Header: /var/cvsroot/gentoo-x86/eclass/mysql-autotools.eclass,v 1.18 2013/06/26 19:31:49 jmbsvicetto Exp $
 
 # @ECLASS: mysql-autotools.eclass
 # @MAINTAINER:
@@ -17,7 +17,7 @@
 # the src_unpack, src_prepare, src_configure, src_compile, scr_install,
 # pkg_preinst, pkg_postinst, pkg_config and pkg_postrm phase hooks.
 
-inherit autotools flag-o-matic multilib
+inherit autotools flag-o-matic multilib prefix
 
 #
 # HELPER FUNCTIONS:
@@ -51,14 +51,14 @@
 	# ${S}/mysql-tests/suite/ndb_team/t/disabled.def
 	# ${S}/mysql-tests/suite/binlog/t/disabled.def
 	# ${S}/mysql-tests/suite/innodb/t/disabled.def
-	if [ -n "${testsuite}" ]; then
+	if [[ -n ${testsuite} ]]; then
 		for mysql_disable_file in \
 			${S}/mysql-test/suite/${testsuite}/disabled.def  \
 			${S}/mysql-test/suite/${testsuite}/t/disabled.def  \
 			FAILED ; do
-			[ -f "${mysql_disable_file}" ] && break
+			[[ -f ${mysql_disable_file} ]] && break
 		done
-		if [ "${mysql_disabled_file}" != "FAILED" ]; then
+		if [[ ${mysql_disabled_file} != "FAILED" ]]; then
 			echo "${testname} : ${reason}" >> "${mysql_disable_file}"
 		else
 			ewarn "Could not find testsuite disabled.def location for ${rawtestname}"
@@ -99,7 +99,7 @@
 
 	# MariaDB requires this flag in order to link to GPLv3 readline v6 or greater
 	# A note is added to the configure output
-	if [[ "${PN}" == "mariadb" ]]  && mysql_version_is_at_least "5.1.61" ; then
+	if [[ ${PN} == "mariadb" ]]  && mysql_version_is_at_least "5.1.61" ; then
 		myconf="${myconf} --disable-distribution"
 	fi
 }
@@ -134,7 +134,7 @@
 		fi
 	fi
 
-	if [ -n "${MYSQL_DEFAULT_CHARSET}" -a -n "${MYSQL_DEFAULT_COLLATION}" ]; then
+	if [[ ( -n ${MYSQL_DEFAULT_CHARSET} ) && ( -n ${MYSQL_DEFAULT_COLLATION} ) ]]; then
 		ewarn "You are using a custom charset of ${MYSQL_DEFAULT_CHARSET}"
 		ewarn "and a collation of ${MYSQL_DEFAULT_COLLATION}."
 		ewarn "You MUST file bugs without these variables set."
@@ -220,7 +220,7 @@
 		# Not supporting as examples: example,daemon_example,ftexample
 		plugins_sta="${plugins_sta} partition"
 
-		if [[ "${PN}" != "mariadb" ]] ; then
+		if [[ ${PN} != "mariadb" ]] ; then
 			elog "Before using the Federated storage engine, please be sure to read"
 			elog "http://dev.mysql.com/doc/refman/5.1/en/federated-limitations.html"
 			plugins_dyn="${plugins_dyn} federated"
@@ -237,10 +237,10 @@
 	# - innobase, innodb_plugin
 	# Build falcon if available for 6.x series.
 	for i in innobase falcon ; do
-		[ -e "${S}"/storage/${i} ] && plugins_sta="${plugins_sta} ${i}"
+		[[ -e ${S}/storage/${i} ]] && plugins_sta="${plugins_sta} ${i}"
 	done
 	for i in innodb_plugin ; do
-		[ -e "${S}"/storage/${i} ] && plugins_dyn="${plugins_dyn} ${i}"
+		[[ -e ${S}/storage/${i} ]] && plugins_dyn="${plugins_dyn} ${i}"
 	done
 
 	# like configuration=max-no-ndb
@@ -252,12 +252,12 @@
 		plugins_dis="${plugins_dis} ndbcluster"
 	fi
 
-	if [[ "${PN}" == "mariadb" ]] ; then
+	if [[ ${PN} == "mariadb" ]] ; then
 		# In MariaDB, InnoDB is packaged in the xtradb directory, so it's not
 		# caught above.
 		# This is not optional, without it several upstream testcases fail.
 		# Also strongly recommended by upstream.
-		if [[ "${PV}" < "5.2.0" ]] ; then
+		if [[ ${PV} < "5.2.0" ]] ; then
 			myconf="${myconf} --with-maria-tmp-tables"
 			plugins_sta="${plugins_sta} maria"
 		else
@@ -265,11 +265,11 @@
 			plugins_sta="${plugins_sta} aria"
 		fi
 
-		[ -e "${S}"/storage/innobase ] || [ -e "${S}"/storage/xtradb ] ||
+		[[ ( -e ${S}/storage/innobase ) || ( -e ${S}/storage/xtradb ) ]] ||
 			die "The ${P} package doesn't provide innobase nor xtradb"
 
 		for i in innobase xtradb ; do
-			[ -e "${S}"/storage/${i} ] && plugins_sta="${plugins_sta} ${i}"
+			[[ -e ${S}/storage/${i} ]] && plugins_sta="${plugins_sta} ${i}"
 		done
 
 		myconf="${myconf} $(use_with libevent)"
@@ -289,9 +289,18 @@
 				|| plugins_dis="${plugins_dis} ${i}"
 			done
 		fi
+
+		#Authentication plugins
+		if mysql_version_is_at_least "5.2.11" ; then
+			for i in pam ; do
+				use ${i} \
+				&& plugins_dyn="${plugins_dyn} auth_${i}" \
+				|| plugins_dis="${plugins_dis} auth_${i}"
+			done
+		fi
 	fi
 
-	if pbxt_available && [[ "${PBXT_NEWSTYLE}" == "1" ]]; then
+	if pbxt_available && [[ ${PBXT_NEWSTYLE} == "1" ]]; then
 		use pbxt \
 		&& plugins_sta="${plugins_sta} pbxt" \
 		|| plugins_dis="${plugins_dis} pbxt"
@@ -301,6 +310,18 @@
 	plugins_sta="${plugins_sta} ${plugins_dyn}" && \
 	plugins_dyn=""
 
+	# Google MySQL, bundle what upstream supports
+	if [[ ${PN} == "google-mysql" ]]; then
+		for x in innobase innodb_plugin innodb ; do
+			plugins_sta="${plugins_sta//$x}"
+			plugins_dyn="${plugins_dyn//$x}"
+		done
+		plugins_sta="${plugins_sta} innodb_plugin googlestats"
+		myconf="${myconf} --with-perftools-dir=/usr --enable-perftools-tcmalloc"
+		# use system lzo for google-mysql
+		myconf="${myconf} --with-lzo2-dir=/usr"
+	fi
+
 	einfo "Available plugins: ${plugins_avail}"
 	einfo "Dynamic plugins: ${plugins_dyn}"
 	einfo "Static plugins: ${plugins_sta}"
@@ -368,7 +389,7 @@
 
 	# last -fPIC fixup, per bug #305873
 	i="${S}"/storage/innodb_plugin/plug.in
-	[ -f "${i}" ] && sed -i -e '/CFLAGS/s,-prefer-non-pic,,g' "${i}"
+	[[ -f ${i} ]] && sed -i -e '/CFLAGS/s,-prefer-non-pic,,g' "${i}"
 
 	# Additional checks, remove bundled zlib
 	rm -f "${S}/zlib/"*.[ch]
@@ -396,19 +417,21 @@
 		i="innobase"
 		o="${WORKDIR}/storage-${i}.mysql-upstream"
 		# Have we been here already?
-		[ -d "${o}" ] && rm -f "${i}"
+		[[ -d ${o} ]] && rm -f "${i}"
 		# Or maybe we haven't
-		[ -d "${i}" -a ! -d "${o}" ] && mv "${i}" "${o}"
+		[[ ( -d ${i} ) && ! ( -d ${o} ) ]] && mv "${i}" "${o}"
 		cp -ral "${WORKDIR}/${XTRADB_P}" "${i}"
 		popd >/dev/null
 	fi
 
-	if pbxt_patch_available && [[ "${PBXT_NEWSTYLE}" == "1" ]] && use pbxt ; then
+	if pbxt_patch_available && [[ ${PBXT_NEWSTYLE} == "1" ]] && use pbxt ; then
 		einfo "Adding storage engine: PBXT"
 		pushd "${S}"/storage >/dev/null
 		i='pbxt'
-		[ -d "${i}" ] && rm -rf "${i}"
+		[[ -d ${i} ]] && rm -rf "${i}"
 		cp -ral "${WORKDIR}/${PBXT_P}" "${i}"
+		f="${WORKDIR}/mysql-extras/pbxt/fix-low-priority.patch"
+		[[ -f $f ]] && epatch "$f"
 		popd >/dev/null
 	fi
 
@@ -433,6 +456,8 @@
 # @DESCRIPTION:
 # Configure mysql to build the code for Gentoo respecting the use flags.
 mysql-autotools_src_configure() {
+	# bug 401733
+	export QA_CONFIGURE_OPTIONS=".*"
 
 	# Make sure the vars are correctly initialized
 	mysql_init_vars
@@ -451,7 +476,7 @@
 	filter-flags "-O" "-O[01]"
 
 	# glib-2.3.2_pre fix, bug #16496
-	append-flags "-DHAVE_ERRNO_AS_DEFINE=1"
+	append-cppflags "-DHAVE_ERRNO_AS_DEFINE=1"
 
 	# As discovered by bug #246652, doing a double-level of SSP causes NDB to
 	# fail badly during cluster startup.
@@ -461,7 +486,11 @@
 
 	CXXFLAGS="${CXXFLAGS} -fno-exceptions -fno-strict-aliasing"
 	CXXFLAGS="${CXXFLAGS} -felide-constructors -fno-rtti"
+	# storage/googlestats, sql/ in google-mysql are using C++ templates
+	# implicitly. Upstream might be interested in this, exclude
+	# -fno-implicit-templates for google-mysql for now.
 	mysql_version_is_at_least "5.0" \
+	&& [[ ${PN} != "google-mysql" ]] \
 	&& CXXFLAGS="${CXXFLAGS} -fno-implicit-templates"
 	export CXXFLAGS
 
@@ -497,7 +526,7 @@
 	| xargs -0 -n100 sed -i \
 	-e 's|^pkglibdir *= *$(libdir)/mysql|pkglibdir = $(libdir)|;s|^pkgincludedir *= *$(includedir)/mysql|pkgincludedir = $(includedir)|'
 
-	if [[ $EAPI == 2 ]] && [[ "${PBXT_NEWSTYLE}" != "1" ]]; then
+	if [[ $EAPI == 2 ]] && [[ ${PBXT_NEWSTYLE} != "1" ]]; then
 		pbxt_patch_available && use pbxt && pbxt_src_configure
 	fi
 }
@@ -509,7 +538,7 @@
 
 	emake || die "emake failed"
 
-	if [[ "${PBXT_NEWSTYLE}" != "1" ]]; then
+	if [[ ${PBXT_NEWSTYLE} != "1" ]]; then
 		pbxt_patch_available && use pbxt && pbxt_src_compile
 	fi
 }
@@ -528,7 +557,7 @@
 		testroot="${MY_SHAREDSTATEDIR}" \
 		|| die "emake install failed"
 
-	if [[ "${PBXT_NEWSTYLE}" != "1" ]]; then
+	if [[ ${PBXT_NEWSTYLE} != "1" ]]; then
 		pbxt_patch_available && use pbxt && pbxt_src_install
 	fi
 
@@ -582,6 +611,7 @@
 			-e "/character-set/s|utf8|latin1|g" \
 			"${TMPDIR}/my.cnf.ok"
 	fi
+	eprefixify "${TMPDIR}/my.cnf.ok"
 	newins "${TMPDIR}/my.cnf.ok" my.cnf
 
 	# Minimal builds don't have the MySQL server
@@ -589,9 +619,8 @@
 		einfo "Creating initial directories"
 		# Empty directories ...
 		diropts "-m0750"
-		if [[ "${PREVIOUS_DATADIR}" != "yes" ]] ; then
-			dodir "${MY_DATADIR#${EPREFIX}}"
-			keepdir "${MY_DATADIR#${EPREFIX}}"
+		keepdir "${MY_DATADIR#${EPREFIX}}"
+		if [[ ${PREVIOUS_DATADIR} != "yes" ]] ; then
 			chown -R mysql:mysql "${D}/${MY_DATADIR}"
 		fi
 
@@ -606,7 +635,7 @@
 	# Docs
 	einfo "Installing docs"
 	for i in README ChangeLog EXCEPTIONS-CLIENT INSTALL-SOURCE ; do
-		[[ -f "$i" ]] && dodoc "$i"
+		[[ -f $i ]] && dodoc "$i"
 	done
 	doinfo "${S}"/Docs/mysql.info
 
@@ -619,15 +648,23 @@
 			"${S}"/support-files/magic \
 			"${S}"/support-files/ndb-config-2-node.ini
 		do
-			[[ -f "$script" ]] && dodoc "${script}"
+			[[ -f $script ]] && dodoc "${script}"
 		done
 
 		docinto "scripts"
 		for script in "${S}"/scripts/mysql* ; do
-			[[ -f "$script" ]] && [[ "${script%.sh}" == "${script}" ]] && dodoc "${script}"
+			[[ ( -f $script ) && ( ${script%.sh} == ${script} ) ]] && dodoc "${script}"
 		done
 
 	fi
 
 	mysql_lib_symlinks "${ED}"
+
+	#Remove mytop if perl is not selected
+	[[ ${PN} == "mariadb" ]] && ! use perl \
+	&& mysql_version_is_at_least "5.3" \
+	&& rm -f "${ED}/usr/bin/mytop"
+
+	#Bug 455462 remove unnecessary libtool files
+	prune_libtool_files --modules
 }
diff --git a/eclass/mysql-cmake.eclass b/eclass/mysql-cmake.eclass
index f634c7f..548bbd3 100644
--- a/eclass/mysql-cmake.eclass
+++ b/eclass/mysql-cmake.eclass
@@ -1,6 +1,6 @@
-# Copyright 1999-2012 Gentoo Foundation
+# Copyright 1999-2013 Gentoo Foundation
 # Distributed under the terms of the GNU General Public License v2
-# $Header: /var/cvsroot/gentoo-x86/eclass/mysql-cmake.eclass,v 1.10 2012/11/01 23:57:50 robbat2 Exp $
+# $Header: /var/cvsroot/gentoo-x86/eclass/mysql-cmake.eclass,v 1.17 2013/06/27 17:23:33 jmbsvicetto Exp $
 
 # @ECLASS: mysql-cmake.eclass
 # @MAINTAINER:
@@ -15,7 +15,7 @@
 # the src_unpack, src_prepare, src_configure, src_compile, scr_install,
 # pkg_preinst, pkg_postinst, pkg_config and pkg_postrm phase hooks.
 
-inherit cmake-utils flag-o-matic multilib
+inherit cmake-utils flag-o-matic multilib prefix
 
 #
 # HELPER FUNCTIONS:
@@ -36,29 +36,29 @@
 	for mysql_disabled_file in \
 		${S}/mysql-test/disabled.def  \
 		${S}/mysql-test/t/disabled.def ; do
-		[ -f "${mysql_disabled_file}" ] && break
+		[[ -f ${mysql_disabled_file} ]] && break
 	done
 	#mysql_disabled_file="${S}/mysql-test/t/disabled.def"
 	#einfo "rawtestname=${rawtestname} testname=${testname} testsuite=${testsuite}"
 	echo ${testname} : ${reason} >> "${mysql_disabled_file}"
 
-	if [ -n "${testsuite}" ] && [ "${testsuite}" != "main" ]; then
+	if [[ ( -n ${testsuite} ) && ( ${testsuite} != "main" ) ]]; then
 		for mysql_disabled_file in \
 			${S}/mysql-test/suite/${testsuite}/disabled.def  \
 			${S}/mysql-test/suite/${testsuite}/t/disabled.def  \
 			FAILED ; do
-			[ -f "${mysql_disabled_file}" ] && break
+			[[ -f ${mysql_disabled_file} ]] && break
 		done
-		if [ "${mysql_disabled_file}" != "FAILED" ]; then
+		if [[ ${mysql_disabled_file} != "FAILED" ]]; then
 			echo "${testname} : ${reason}" >> "${mysql_disabled_file}"
 		else
 			for mysql_disabled_dir in \
 				${S}/mysql-test/suite/${testsuite} \
 				${S}/mysql-test/suite/${testsuite}/t  \
 				FAILED ; do
-				[ -d "${mysql_disabled_dir}" ] && break
+				[[ -d ${mysql_disabled_dir} ]] && break
 			done
-			if [ "${mysql_disabled_dir}" != "FAILED" ]; then
+			if [[ ${mysql_disabled_dir} != "FAILED" ]]; then
 				echo "${testname} : ${reason}" >> "${mysql_disabled_dir}/disabled.def"
 			else
 				ewarn "Could not find testsuite disabled.def location for ${rawtestname}"
@@ -72,7 +72,7 @@
 # Helper function to configure locale cmake options
 configure_cmake_locale() {
 
-	if ! use minimal && [ -n "${MYSQL_DEFAULT_CHARSET}" -a -n "${MYSQL_DEFAULT_COLLATION}" ]; then
+	if ! use minimal && [[ ( -n ${MYSQL_DEFAULT_CHARSET} ) && ( -n ${MYSQL_DEFAULT_COLLATION} ) ]]; then
 		ewarn "You are using a custom charset of ${MYSQL_DEFAULT_CHARSET}"
 		ewarn "and a collation of ${MYSQL_DEFAULT_COLLATION}."
 		ewarn "You MUST file bugs without these variables set."
@@ -109,7 +109,8 @@
 		-DWITH_SSL=system
 		-DWITH_ZLIB=system
 		-DWITHOUT_LIBWRAP=1
-		-DWITHOUT_READLINE=1
+		-DWITH_READLINE=0
+		-DWITH_LIBEDIT=0
 		-DWITHOUT_ARCHIVE_STORAGE_ENGINE=1
 		-DWITHOUT_BLACKHOLE_STORAGE_ENGINE=1
 		-DWITHOUT_CSV_STORAGE_ENGINE=1
@@ -133,7 +134,8 @@
 		-DEXTRA_CHARSETS=all
 		-DMYSQL_USER=mysql
 		-DMYSQL_UNIX_ADDR=${EPREFIX}/var/run/mysqld/mysqld.sock
-		-DWITHOUT_READLINE=1
+		-DWITH_READLINE=0
+		-DWITH_LIBEDIT=0
 		-DWITH_ZLIB=system
 		-DWITHOUT_LIBWRAP=1
 	)
@@ -149,7 +151,7 @@
 	if use ssl; then
 		mycmakeargs+=( -DWITH_SSL=system )
 	else
-		mycmakeargs+=( -DWITH_SSL=0 )
+		mycmakeargs+=( -DWITH_SSL=bundled )
 	fi
 
 	if mysql_version_is_at_least "5.5" && use jemalloc; then
@@ -177,12 +179,22 @@
 		mycmakeargs+=( $(cmake-utils_use_with pbxt PBXT_STORAGE_ENGINE) )
 	fi
 
-	if [ "${PN}" == "mariadb" ]; then
+	if [[ ${PN} == "mariadb" ]]; then
 		mycmakeargs+=(
 			$(cmake-utils_use_with oqgraph OQGRAPH_STORAGE_ENGINE)
 			$(cmake-utils_use_with sphinx SPHINX_STORAGE_ENGINE)
 			$(cmake-utils_use_with extraengine FEDERATEDX_STORAGE_ENGINE)
 		)
+
+		if ! use pam ; then
+			mycmakeargs+=( -DAUTH_PAM_DISABLED=1 )
+		fi
+	fi
+
+	if [[ ${PN} == "percona-server" ]]; then
+		mycmakeargs+=(
+			$(cmake-utils_use_with pam)
+		)
 	fi
 }
 
@@ -211,9 +223,10 @@
 
 	# last -fPIC fixup, per bug #305873
 	i="${S}"/storage/innodb_plugin/plug.in
-	[ -f "${i}" ] && sed -i -e '/CFLAGS/s,-prefer-non-pic,,g' "${i}"
+	[[ -f ${i} ]] && sed -i -e '/CFLAGS/s,-prefer-non-pic,,g' "${i}"
 
 	rm -f "scripts/mysqlbug"
+	epatch_user
 }
 
 # @FUNCTION: mysql-cmake_src_configure
@@ -245,13 +258,13 @@
 		-DINSTALL_SQLBENCHDIR=share/mysql
 		-DINSTALL_SUPPORTFILESDIR=${EPREFIX}/usr/share/mysql
 		-DWITH_COMMENT="Gentoo Linux ${PF}"
-		-DWITHOUT_UNIT_TESTS=1
+		$(cmake-utils_use_with test UNIT_TESTS)
 	)
 
 	# Bug 412851
 	# MariaDB requires this flag to compile with GPLv3 readline linked
 	# Adds a warning about redistribution to configure
-	if [[ "${PN}" == "mariadb" ]] ; then
+	if [[ ${PN} == "mariadb" ]] ; then
 		mycmakeargs+=( -DNOT_FOR_DISTRIBUTION=1 )
 	fi
 
@@ -266,9 +279,16 @@
 	# Bug #114895, bug #110149
 	filter-flags "-O" "-O[01]"
 
-	CXXFLAGS="${CXXFLAGS} -fno-exceptions -fno-strict-aliasing"
+	CXXFLAGS="${CXXFLAGS} -fno-strict-aliasing"
 	CXXFLAGS="${CXXFLAGS} -felide-constructors -fno-rtti"
-	CXXFLAGS="${CXXFLAGS} -fno-implicit-templates"
+	# Causes linkage failures.  Upstream bug #59607 removes it
+	if ! mysql_version_is_at_least "5.6" ; then
+		CXXFLAGS="${CXXFLAGS} -fno-implicit-templates"
+	fi
+	# As of 5.7, exceptions are used!
+	if ! mysql_version_is_at_least "5.7" ; then
+		CXXFLAGS="${CXXFLAGS} -fno-exceptions"
+	fi
 	export CXXFLAGS
 
 	# bug #283926, with GCC4.4, this is required to get correct behavior.
@@ -305,6 +325,9 @@
 	dosym "/usr/bin/mysqlcheck" "/usr/bin/mysqlrepair"
 	dosym "/usr/bin/mysqlcheck" "/usr/bin/mysqloptimize"
 
+	# Create a mariadb_config symlink
+	[[ ${PN} == "mariadb" ]] && dosym "/usr/bin/mysql_config" "/usr/bin/mariadb_config"
+
 	# INSTALL_LAYOUT=STANDALONE causes cmake to create a /usr/data dir
 	rm -Rf "${ED}/usr/data"
 
@@ -329,10 +352,11 @@
 
 	# Configuration stuff
 	case ${MYSQL_PV_MAJOR} in
-		5.[1-9]|6*|7*) mysql_mycnf_version="5.1" ;;
+		5.[1-4]*) mysql_mycnf_version="5.1" ;;
+		5.[5-9]|6*|7*|8*|9*|10*) mysql_mycnf_version="5.5" ;;
 	esac
 	einfo "Building default my.cnf (${mysql_mycnf_version})"
-	insinto "${MY_SYSCONFDIR}"
+	insinto "${MY_SYSCONFDIR#${EPREFIX}}"
 	doins scripts/mysqlaccess.conf
 	mycnf_src="my.cnf-${mysql_mycnf_version}"
 	sed -e "s!@DATADIR@!${MY_DATADIR}!g" \
@@ -343,6 +367,7 @@
 			-e "/character-set/s|utf8|latin1|g" \
 			"${TMPDIR}/my.cnf.ok"
 	fi
+	eprefixify "${TMPDIR}/my.cnf.ok"
 	newins "${TMPDIR}/my.cnf.ok" my.cnf
 
 	# Minimal builds don't have the MySQL server
@@ -350,7 +375,7 @@
 		einfo "Creating initial directories"
 		# Empty directories ...
 		diropts "-m0750"
-		if [[ "${PREVIOUS_DATADIR}" != "yes" ]] ; then
+		if [[ ${PREVIOUS_DATADIR} != "yes" ]] ; then
 			dodir "${MY_DATADIR#${EPREFIX}}"
 			keepdir "${MY_DATADIR#${EPREFIX}}"
 			chown -R mysql:mysql "${D}/${MY_DATADIR}"
@@ -373,15 +398,21 @@
 			"${S}"/support-files/magic \
 			"${S}"/support-files/ndb-config-2-node.ini.sh
 		do
-			[[ -f "$script" ]] && dodoc "${script}"
+			[[ -f $script ]] && dodoc "${script}"
 		done
 
 		docinto "scripts"
 		for script in "${S}"/scripts/mysql* ; do
-			[[ -f "$script" ]] && [[ "${script%.sh}" == "${script}" ]] && dodoc "${script}"
+			[[ ( -f $script ) && ( ${script%.sh} == ${script} ) ]] && dodoc "${script}"
 		done
-
 	fi
 
-	mysql_lib_symlinks "${ED}"
+	cat <<-EOF > "${T}"/80mysql-libdir
+	LDPATH="${EPREFIX}/usr/$(get_libdir)/mysql"
+	EOF
+	doenvd "${T}"/80mysql-libdir
+
+	#Remove mytop if perl is not selected
+	[[ ${PN} == "mariadb" ]] && ! use perl \
+	&& rm -f "${ED}/usr/bin/mytop"
 }
diff --git a/eclass/mysql-v2.eclass b/eclass/mysql-v2.eclass
index ac20d17..f288215 100644
--- a/eclass/mysql-v2.eclass
+++ b/eclass/mysql-v2.eclass
@@ -1,6 +1,6 @@
 # Copyright 1999-2012 Gentoo Foundation
 # Distributed under the terms of the GNU General Public License v2
-# $Header: /var/cvsroot/gentoo-x86/eclass/mysql-v2.eclass,v 1.21 2012/11/01 23:57:50 robbat2 Exp $
+# $Header: /var/cvsroot/gentoo-x86/eclass/mysql-v2.eclass,v 1.26 2014/01/08 06:20:29 vapier Exp $
 
 # @ECLASS: mysql-v2.eclass
 # @MAINTAINER:
@@ -11,7 +11,7 @@
 # @BLURB: This eclass provides most of the functions for mysql ebuilds
 # @DESCRIPTION:
 # The mysql-v2.eclass is the base eclass to build the mysql and
-# alternative projects (mariadb) ebuilds.
+# alternative projects (mariadb and percona) ebuilds.
 # This eclass uses the mysql-autotools and mysql-cmake eclasses for the
 # specific bits related to the build system.
 # It provides the src_unpack, src_prepare, src_configure, src_compile,
@@ -44,16 +44,16 @@
 # @DESCRIPTION:
 # The version of the MYSQL_EXTRAS repo to use to build mysql
 # Use "none" to disable it's use
-[[ "${MY_EXTRAS_VER}" == "live" ]] && MYSQL_EXTRAS="git-2"
+[[ ${MY_EXTRAS_VER} == "live" ]] && MYSQL_EXTRAS="git-2"
 
-inherit eutils flag-o-matic gnuconfig ${MYSQL_EXTRAS} ${BUILD_INHERIT} mysql_fx versionator toolchain-funcs
+inherit eutils flag-o-matic gnuconfig ${MYSQL_EXTRAS} ${BUILD_INHERIT} mysql_fx versionator toolchain-funcs user
 
 #
 # Supported EAPI versions and export functions
 #
 
 case "${EAPI:-0}" in
-	3|4|5) ;;
+	4|5) ;;
 	*) die "Unsupported EAPI: ${EAPI}" ;;
 esac
 
@@ -67,8 +67,8 @@
 # and we will run a mysql server during test phase
 S="${WORKDIR}/mysql"
 
-[[ "${MY_EXTRAS_VER}" == "latest" ]] && MY_EXTRAS_VER="20090228-0714Z"
-if [[ "${MY_EXTRAS_VER}" == "live" ]]; then
+[[ ${MY_EXTRAS_VER} == "latest" ]] && MY_EXTRAS_VER="20090228-0714Z"
+if [[ ${MY_EXTRAS_VER} == "live" ]]; then
 	EGIT_PROJECT=mysql-extras
 	EGIT_REPO_URI="git://git.overlays.gentoo.org/proj/mysql-extras.git"
 fi
@@ -113,10 +113,10 @@
 # Designation by PERCONA for a MySQL version to apply an XTRADB release
 
 # Work out the default SERVER_URI correctly
-if [ -z "${SERVER_URI}" ]; then
-	[ -z "${MY_PV}" ] && MY_PV="${PV//_/-}"
-	if [ "${PN}" == "mariadb" ]; then
-		MARIA_FULL_PV="$(replace_version_separator 3 '-' ${MY_PV})"
+if [[ -z ${SERVER_URI} ]]; then
+	[[ -z ${MY_PV} ]] && MY_PV="${PV//_/-}"
+	if [[ ${PN} == "mariadb" || ${PN} == "mariadb-galera" ]]; then
+		MARIA_FULL_PV=$(replace_version_separator 3 '-' ${MY_PV})
 		MARIA_FULL_P="${PN}-${MARIA_FULL_PV}"
 		SERVER_URI="
 		http://ftp.osuosl.org/pub/mariadb/${MARIA_FULL_P}/kvm-tarbake-jaunty-x86/${MARIA_FULL_P}.tar.gz
@@ -126,6 +126,16 @@
 		http://mirrors.fe.up.pt/pub/${PN}/${MARIA_FULL_P}/kvm-tarbake-jaunty-x86/${MARIA_FULL_P}.tar.gz
 		http://ftp-stud.hs-esslingen.de/pub/Mirrors/${PN}/${MARIA_FULL_P}/kvm-tarbake-jaunty-x86/${MARIA_FULL_P}.tar.gz
 		"
+		if [[ ${PN} == "mariadb-galera" ]]; then
+			MY_SOURCEDIR="${PN%%-galera}-${MARIA_FULL_PV}"
+		fi
+	elif [[ ${PN} == "percona-server" ]]; then
+		PERCONA_PN="Percona-Server"
+		MIRROR_PV=$(get_version_component_range 1-2 ${PV})
+		MY_PV=$(get_version_component_range 1-3 ${PV})
+		MY_PATCH=$(get_version_component_range 4 ${PV})
+		SERVER_URI="http://www.percona.com/redir/downloads/${PERCONA_PN}-${MIRROR_PV}/LATEST/source/${PERCONA_PN}-${MY_PV}-rel30.${MY_PATCH}.tar.gz"
+#		http://www.percona.com/redir/downloads/Percona-Server-5.5/LATEST/source/Percona-Server-5.5.30-rel30.2.tar.gz
 	else
 		URI_DIR="MySQL"
 		URI_FILE="mysql"
@@ -141,18 +151,27 @@
 SRC_URI="${SERVER_URI}"
 
 # Gentoo patches to MySQL
-[[ ${MY_EXTRAS_VER} != live ]] && [[ ${MY_EXTRAS_VER} != none ]] \
-&& SRC_URI="${SRC_URI}
+if [[ ${MY_EXTRAS_VER} != "live" && ${MY_EXTRAS_VER} != "none" ]]; then
+	SRC_URI="${SRC_URI}
 		mirror://gentoo/mysql-extras-${MY_EXTRAS_VER}.tar.bz2
 		http://g3nt8.org/patches/mysql-extras-${MY_EXTRAS_VER}.tar.bz2
 		http://dev.gentoo.org/~robbat2/distfiles/mysql-extras-${MY_EXTRAS_VER}.tar.bz2
 		http://dev.gentoo.org/~jmbsvicetto/distfiles/mysql-extras-${MY_EXTRAS_VER}.tar.bz2"
+fi
 
 DESCRIPTION="A fast, multi-threaded, multi-user SQL database server."
 HOMEPAGE="http://www.mysql.com/"
-if [[ "${PN}" == "mariadb" ]]; then
+if [[ ${PN} == "mariadb" ]]; then
 	HOMEPAGE="http://mariadb.org/"
-	DESCRIPTION="MariaDB is a MySQL fork with 3rd-party patches and additional storage engines merged."
+	DESCRIPTION="An enhanced, drop-in replacement for MySQL"
+fi
+if [[ ${PN} == "mariadb-galera" ]]; then
+	HOMEPAGE="http://mariadb.org/"
+	DESCRIPTION="An enhanced, drop-in replacement for MySQL with Galera Replication"
+fi
+if [[ ${PN} == "percona-server" ]]; then
+	HOMEPAGE="http://www.percona.com/software/percona-server"
+	DESCRIPTION="An enhanced, drop-in replacement fro MySQL from the Percona team"
 fi
 LICENSE="GPL-2"
 SLOT="0"
@@ -172,28 +191,29 @@
 IUSE="${IUSE} cluster"
 
 IUSE="${IUSE} max-idx-128"
-IUSE="${IUSE} berkdb"
 IUSE="${IUSE} +community profiling"
 
-[[ ${PN} == "mariadb" ]] \
-&& mysql_check_version_range "5.1.38 to 5.3.99" \
-&& IUSE="${IUSE} libevent"
-
-[[ ${PN} == "mariadb" ]] \
-&& mysql_version_is_at_least "5.2" \
-&& IUSE="${IUSE} oqgraph"
-
-[[ ${PN} == "mariadb" ]] \
-&& mysql_version_is_at_least "5.2.5" \
-&& IUSE="${IUSE} sphinx"
+if [[ ${PN} == "mariadb" || ${PN} == "mariadb-galera" ]]; then
+	mysql_check_version_range "5.1.38 to 5.3.99" && IUSE="${IUSE} libevent"
+	mysql_version_is_at_least "5.2" && IUSE="${IUSE} oqgraph"
+	mysql_version_is_at_least "5.2.5" && IUSE="${IUSE} sphinx"
+	mysql_version_is_at_least "5.2.10" && IUSE="${IUSE} pam"
+fi
 
 if mysql_version_is_at_least "5.5"; then
 	REQUIRED_USE="tcmalloc? ( !jemalloc ) jemalloc? ( !tcmalloc )"
 	IUSE="${IUSE} jemalloc tcmalloc"
 fi
 
-mysql_version_is_at_least "5.5.7" \
-&& IUSE="${IUSE} systemtap"
+if mysql_version_is_at_least "5.5.7"; then
+	IUSE="${IUSE} systemtap"
+fi
+
+if [[ ${PN} == "percona-server" ]]; then
+	mysql_version_is_at_least "5.5.10" && IUSE="${IUSE} pam"
+fi
+
+REQUIRED_USE="${REQUIRED_USE} minimal? ( !cluster !extraengine !embedded ) static? ( !ssl )"
 
 #
 # DEPENDENCIES:
@@ -210,22 +230,48 @@
 	>=sys-libs/zlib-1.2.3
 "
 
-[[ ${PN} == mariadb ]] \
-&& mysql_check_version_range "5.1.38 to 5.3.99" \
-&& DEPEND="${DEPEND} libevent? ( >=dev-libs/libevent-1.4 )"
+if [[ ${PN} == "mariadb" || ${PN} == "mariadb-galera" ]] ; then
+	mysql_check_version_range "5.1.38 to 5.3.99" && DEPEND="${DEPEND} libevent? ( >=dev-libs/libevent-1.4 )"
+	mysql_version_is_at_least "5.2" && DEPEND="${DEPEND} oqgraph? ( >=dev-libs/boost-1.40.0 )"
+	mysql_version_is_at_least "5.2.5" && DEPEND="${DEPEND} sphinx? ( app-misc/sphinx )"
+	mysql_version_is_at_least "5.2.10" && DEPEND="${DEPEND} !minimal? ( pam? ( virtual/pam ) )"
+	# Bug 441700 MariaDB >=5.3 include custom mytop
+	mysql_version_is_at_least "5.3" && DEPEND="${DEPEND} perl? ( !dev-db/mytop )"
+fi
 
 # Having different flavours at the same time is not a good idea
-for i in "mysql" "mariadb" ; do
+for i in "mysql" "mariadb" "mariadb-galera" "percona-server"; do
 	[[ ${i} == ${PN} ]] ||
 	DEPEND="${DEPEND} !dev-db/${i}"
 done
 
+if mysql_version_is_at_least "5.5" ; then
+	DEPEND="${DEPEND} jemalloc? ( dev-libs/jemalloc )"
+	DEPEND="${DEPEND} tcmalloc? ( dev-util/google-perftools )"
+fi
+
+if mysql_version_is_at_least "5.5.7" ; then
+	DEPEND="${DEPEND} systemtap? ( >=dev-util/systemtap-1.3 )"
+	DEPEND="${DEPEND} kernel_linux? ( dev-libs/libaio )"
+fi
+
 # prefix: first need to implement something for #196294
 RDEPEND="${DEPEND}
 	!minimal? ( !prefix? ( dev-db/mysql-init-scripts ) )
 	selinux? ( sec-policy/selinux-mysql )
 "
 
+if [[ ${PN} == "mariadb" || ${PN} == "mariadb-galera" ]] ; then
+	# Bug 455016 Add dependencies of mytop
+	if mysql_version_is_at_least "5.3" ; then
+		RDEPEND="${RDEPEND} perl? (
+			virtual/perl-Getopt-Long
+			dev-perl/TermReadKey
+			virtual/perl-Term-ANSIColor
+			virtual/perl-Time-HiRes ) "
+	fi
+fi
+
 DEPEND="${DEPEND}
 	virtual/yacc
 "
@@ -236,26 +282,9 @@
 DEPEND="${DEPEND} >=dev-util/cmake-2.4.3"
 
 # compile-time-only
-mysql_version_is_at_least "5.5.8" \
-&& DEPEND="${DEPEND} >=dev-util/cmake-2.6.3"
-
-[[ "${PN}" == "mariadb" ]] \
-&& mysql_version_is_at_least "5.2" \
-&& DEPEND="${DEPEND} oqgraph? ( >=dev-libs/boost-1.40.0 )"
-
-[[ "${PN}" == "mariadb" ]] \
-&& mysql_version_is_at_least "5.2.5" \
-&& DEPEND="${DEPEND} sphinx? ( app-misc/sphinx )"
-
-mysql_version_is_at_least "5.5.7" \
-&& DEPEND="${DEPEND} systemtap? ( >=dev-util/systemtap-1.3 )" \
-&& DEPEND="${DEPEND} kernel_linux? ( dev-libs/libaio )"
-
-mysql_version_is_at_least "5.5" \
-&& DEPEND="${DEPEND} jemalloc? ( dev-libs/jemalloc )"
-
-mysql_version_is_at_least "5.5" \
-&& DEPEND="${DEPEND} tcmalloc? ( dev-util/google-perftools )"
+if mysql_version_is_at_least "5.5.8" ; then
+	DEPEND="${DEPEND} >=dev-util/cmake-2.6.3"
+fi
 
 # dev-perl/DBD-mysql is needed by some scripts installed by MySQL
 PDEPEND="perl? ( >=dev-perl/DBD-mysql-2.9004 )"
@@ -271,13 +300,12 @@
 # PBXT_VERSION means that we have a PBXT patch for this PV
 # PBXT was only introduced after 5.1.12
 pbxt_patch_available() {
-	[[ ${PN} != "mariadb" ]] \
-	&& [[ -n "${PBXT_VERSION}" ]]
+	[[ ${PN} != "mariadb" && ${PN} != "mariadb-galera" && ( -n "${PBXT_VERSION}" ) ]]
 	return $?
 }
 
 pbxt_available() {
-	pbxt_patch_available || [[ ${PN} == "mariadb" ]]
+	pbxt_patch_available || [[ ${PN} == "mariadb" || ${PN} == "mariadb-galera" ]]
 	return $?
 }
 
@@ -286,18 +314,16 @@
 # XTRADB_VERS means that we have a XTRADB patch for this PV
 # XTRADB was only introduced after 5.1.26
 xtradb_patch_available() {
-	[[ ${PN} != "mariadb" ]] \
-	&& [[ -n "${XTRADB_VER}" && -n "${PERCONA_VER}" ]]
+	[[ ${PN} != "mariadb" && ${PN} != "mariadb-galera"
+		&& ( -n "${XTRADB_VER}" ) && ( -n "${PERCONA_VER}" ) ]]
 	return $?
 }
 
-
 if pbxt_patch_available; then
 
 	PBXT_P="pbxt-${PBXT_VERSION}"
 	PBXT_SRC_URI="http://www.primebase.org/download/${PBXT_P}.tar.gz mirror://sourceforge/pbxt/${PBXT_P}.tar.gz"
 	SRC_URI="${SRC_URI} pbxt? ( ${PBXT_SRC_URI} )"
-
 fi
 
 # PBXT_NEWSTYLE means pbxt is in storage/ and gets enabled as other plugins
@@ -306,6 +332,7 @@
 
 	IUSE="${IUSE} pbxt"
 	PBXT_NEWSTYLE=1
+	REQUIRED_USE="${REQUIRED_USE} pbxt? ( !embedded ) "
 fi
 
 if xtradb_patch_available; then
@@ -318,6 +345,7 @@
 	XTRADB_SRC_URI3="${XTRADB_SRC_B1}/${PN}/xtradb/${XTRADB_SRC_URI_COMMON}"
 	SRC_URI="${SRC_URI} xtradb? ( ${XTRADB_SRC_URI1} ${XTRADB_SRC_URI2} ${XTRADB_SRC_URI3} )"
 	IUSE="${IUSE} xtradb"
+	REQUIRED_USE="${REQUIRED_USE} xtradb? ( !embedded ) "
 fi
 
 #
@@ -367,33 +395,11 @@
 	fi
 
 	# Check for USE flag problems in pkg_setup
-	if use static && use ssl ; then
-		M="MySQL does not support being built statically with SSL support enabled!"
-		eerror "${M}"
-		die "${M}"
-	fi
-
-	if ! mysql_version_is_at_least "5.2" \
-		&& use debug ; then
+	if ! mysql_version_is_at_least "5.2" && use debug ; then
 		# Also in package.use.mask
 		die "Bug #344885: Upstream has broken USE=debug for 5.1 series >=5.1.51"
 	fi
 
-	if ( use cluster || use extraengine || use embedded ) \
-	&& use minimal ; then
-		M="USE flags 'cluster', 'extraengine', 'embedded' conflict with 'minimal' USE flag!"
-		eerror "${M}"
-		die "${M}"
-	fi
-
-	if xtradb_patch_available \
-	&& use xtradb \
-	&& use embedded ; then
-		M="USE flags 'xtradb' and 'embedded' conflict and cause build failures"
-		eerror "${M}"
-		die "${M}"
-	fi
-
 	# This should come after all of the die statements
 	enewgroup mysql 60 || die "problem adding 'mysql' group"
 	enewuser mysql 60 -1 /dev/null mysql || die "problem adding 'mysql' user"
@@ -491,11 +497,20 @@
 
 		docinto "scripts"
 		for script in scripts/mysql* ; do
-			[[ -f "${script}" ]] \
-			&& [[ "${script%.sh}" == "${script}" ]] \
-			&& dodoc "${script}"
+			if [[ -f "${script}" && "${script%.sh}" == "${script}" ]]; then
+				dodoc "${script}"
+			fi
 		done
 
+		if [[ ${PN} == "mariadb" || ${PN} == "mariadb-galera" ]] \
+			&& mysql_version_is_at_least "5.2.10" && use pam ; then
+			einfo
+			elog "This install includes the PAM authentication plugin."
+			elog "To activate and configure the PAM plugin, please read:"
+			elog "https://kb.askmonty.org/en/pam-authentication-plugin/"
+			einfo
+		fi
+
 		einfo
 		elog "You might want to run:"
 		elog "\"emerge --config =${CATEGORY}/${PF}\""
@@ -522,10 +537,6 @@
 		elog "      PRIMARY KEY (name)"
 		elog "    ) CHARACTER SET utf8 COLLATE utf8_bin;"
 	fi
-
-	mysql_check_version_range "4.0 to 5.0.99.99" \
-	&& use berkdb \
-	&& elog "Berkeley DB support is deprecated and will be removed in future versions!"
 }
 
 # @FUNCTION: mysql-v2_getopt
@@ -573,7 +584,7 @@
 		local old_MY_DATADIR_s="${ROOT}/${old_MY_DATADIR}"
 		old_MY_DATADIR_s="${old_MY_DATADIR_s%%/}"
 
-		if [[ -d "${old_MY_DATADIR_s}" ]] && [[ "${old_MY_DATADIR_s}" != / ]]; then
+		if [[ ( -d "${old_MY_DATADIR_s}" ) && ( "${old_MY_DATADIR_s}" != / ) ]]; then
 			if [[ -d "${MY_DATADIR_s}" ]]; then
 				ewarn "Both ${old_MY_DATADIR_s} and ${MY_DATADIR_s} exist"
 				ewarn "Attempting to use ${MY_DATADIR_s} and preserving ${old_MY_DATADIR_s}"
@@ -656,11 +667,11 @@
 	&& cp "${help_tables}" "${TMPDIR}/fill_help_tables.sql" \
 	|| touch "${TMPDIR}/fill_help_tables.sql"
 	help_tables="${TMPDIR}/fill_help_tables.sql"
-	
+
 	# Figure out which options we need to disable to do the setup
 	helpfile="${TMPDIR}/mysqld-help"
 	${EROOT}/usr/sbin/mysqld --verbose --help >"${helpfile}" 2>/dev/null
-	for opt in grant-tables host-cache name-resolve networking slave-start bdb \
+	for opt in grant-tables host-cache name-resolve networking slave-start \
 		federated innodb ssl log-bin relay-log slow-query-log external-locking \
 		ndbcluster log-slave-updates \
 		; do
@@ -676,7 +687,7 @@
 	pushd "${TMPDIR}" &>/dev/null
 	#cmd="'${EROOT}/usr/share/mysql/scripts/mysql_install_db' '--basedir=${EPREFIX}/usr' ${options}"
 	cmd=${EROOT}usr/share/mysql/scripts/mysql_install_db
-	[ -f ${cmd} ] || cmd=${EROOT}usr/bin/mysql_install_db
+	[[ -f ${cmd} ]] || cmd=${EROOT}usr/bin/mysql_install_db
 	cmd="'$cmd' '--basedir=${EPREFIX}/usr' ${options}"
 	einfo "Command: $cmd"
 	eval $cmd \
@@ -702,6 +713,14 @@
 	einfo "Creating the mysql database and setting proper"
 	einfo "permissions on it ..."
 
+	# Now that /var/run is a tmpfs mount point, we need to ensure it exists before using it
+	PID_DIR="${EROOT}/var/run/mysqld"
+	if [[ ! -d "${PID_DIR}" ]]; then
+		mkdir "${PID_DIR}"
+		chown mysql:mysql "${PID_DIR}"
+		chmod 755 "${PID_DIR}"
+	fi
+
 	local socket="${EROOT}/var/run/mysqld/mysqld${RANDOM}.sock"
 	local pidfile="${EROOT}/var/run/mysqld/mysqld${RANDOM}.pid"
 	local mysqld="${EROOT}/usr/sbin/mysqld \
@@ -749,7 +768,7 @@
 		mysql < "${sqltmp}"
 	rc=$?
 	eend $?
-	[ $rc -ne 0 ] && ewarn "Failed to load zoneinfo!"
+	[[ $rc -ne 0 ]] && ewarn "Failed to load zoneinfo!"
 
 	# Stop the server and cleanup
 	einfo "Stopping the server ..."
diff --git a/eclass/mysql.eclass b/eclass/mysql.eclass
index faa8acc..56468ed 100644
--- a/eclass/mysql.eclass
+++ b/eclass/mysql.eclass
@@ -1,13 +1,14 @@
-# Copyright 1999-2009 Gentoo Foundation
+# Copyright 1999-2013 Gentoo Foundation
 # Distributed under the terms of the GNU General Public License v2
-# $Header: /var/cvsroot/gentoo-x86/eclass/mysql.eclass,v 1.136 2010/03/09 20:37:34 robbat2 Exp $
+# $Header: /var/cvsroot/gentoo-x86/eclass/mysql.eclass,v 1.178 2014/01/08 06:20:29 vapier Exp $
 
 # @ECLASS: mysql.eclass
 # @MAINTAINER:
-# Author: Francesco Riosa (Retired) <vivo@gentoo.org>
-# Maintainers: MySQL Team <mysql-bugs@gentoo.org>
-#		- Luca Longinotti <chtekk@gentoo.org>
-#		- Robin H. Johnson <robbat2@gentoo.org>
+# MySQL Team <mysql-bugs@gentoo.org>
+# Luca Longinotti <chtekk@gentoo.org>
+# Robin H. Johnson <robbat2@gentoo.org>
+# @AUTHOR:
+# Francesco Riosa (Retired) <vivo@gentoo.org>
 # @BLURB: This eclass provides most of the functions for mysql ebuilds
 # @DESCRIPTION:
 # The mysql.eclass provides almost all the code to build the mysql ebuilds
@@ -18,7 +19,7 @@
 WANT_AUTOCONF="latest"
 WANT_AUTOMAKE="latest"
 
-inherit eutils flag-o-matic gnuconfig autotools mysql_fx versionator toolchain-funcs
+inherit eutils flag-o-matic gnuconfig autotools multilib mysql_fx versionator toolchain-funcs user
 
 # Shorten the path because the socket path length must be shorter than 107 chars
 # and we will run a mysql server during test phase
@@ -28,11 +29,11 @@
 if [[ "${MY_EXTRAS_VER}" == "live" ]]; then
 	EGIT_PROJECT=mysql-extras
 	EGIT_REPO_URI="git://git.overlays.gentoo.org/proj/mysql-extras.git"
-	inherit git
+	inherit git-2
 fi
 
 case "${EAPI:-0}" in
-	2)
+	2|3|4|5)
 		EXPORT_FUNCTIONS pkg_setup \
 					src_unpack src_prepare \
 					src_configure src_compile \
@@ -53,6 +54,22 @@
 		die "Unsupported EAPI: ${EAPI}" ;;
 esac
 
+
+# @ECLASS-VARIABLE: MYSQL_PV_MAJOR
+# @DESCRIPTION:
+# Upstream MySQL considers the first two parts of the version number to be the
+# major version. Upgrades that change major version should always run
+# mysql_upgrade.
+MYSQL_PV_MAJOR="$(get_version_component_range 1-2 ${PV})"
+
+# Cluster is a special case...
+if [[ "${PN}" == "mysql-cluster" ]]; then
+	case $PV in
+		6.1*|7.0*|7.1*) MYSQL_PV_MAJOR=5.1 ;;
+	esac
+fi
+
+
 # @ECLASS-VARIABLE: MYSQL_VERSION_ID
 # @DESCRIPTION:
 # MYSQL_VERSION_ID will be:
@@ -79,7 +96,7 @@
 # and 0 (no).
 # Community features are available in mysql-community
 # AND in the re-merged mysql-5.0.82 and newer
-if [ "${PN}" == "mysql-community" ]; then
+if [ "${PN}" == "mysql-community" -o "${PN}" == "mariadb" ]; then
 	MYSQL_COMMUNITY_FEATURES=1
 elif [ "${PV#5.0}" != "${PV}" ] && mysql_version_is_at_least "5.0.82"; then
 	MYSQL_COMMUNITY_FEATURES=1
@@ -89,7 +106,9 @@
 	MYSQL_COMMUNITY_FEATURES=1
 elif [ "${PV#5.5}" != "${PV}" ] ; then
 	MYSQL_COMMUNITY_FEATURES=1
-elif [ "${PV#6.0}" != "${PV}" ] ; then
+elif [ "${PV#6}" != "${PV}" ] ; then
+	MYSQL_COMMUNITY_FEATURES=1
+elif [ "${PV#7}" != "${PV}" ] ; then
 	MYSQL_COMMUNITY_FEATURES=1
 else
 	MYSQL_COMMUNITY_FEATURES=0
@@ -108,22 +127,33 @@
 # Be warned, *DEPEND are version-dependant
 # These are used for both runtime and compiletime
 DEPEND="ssl? ( >=dev-libs/openssl-0.9.6d )
-		userland_GNU? ( sys-process/procps )
+		kernel_linux? ( sys-process/procps )
 		>=sys-apps/sed-4
 		>=sys-apps/texinfo-4.7-r1
 		>=sys-libs/readline-4.1
 		>=sys-libs/zlib-1.2.3"
 
+[[ "${PN}" == "mariadb" ]] \
+&& DEPEND="${DEPEND} libevent? ( >=dev-libs/libevent-1.4 )"
+
 # Having different flavours at the same time is not a good idea
-for i in "" "-community" ; do
-	[[ "${i}" == ${PN#mysql} ]] ||
-	DEPEND="${DEPEND} !dev-db/mysql${i}"
+for i in "mysql" "mysql-community" "mysql-cluster" "mariadb" ; do
+	[[ "${i}" == ${PN} ]] ||
+	DEPEND="${DEPEND} !dev-db/${i}"
 done
 
+# prefix: first need to implement something for #196294
 RDEPEND="${DEPEND}
-		!minimal? ( dev-db/mysql-init-scripts )
+		!minimal? ( !prefix? ( dev-db/mysql-init-scripts ) )
 		selinux? ( sec-policy/selinux-mysql )"
 
+DEPEND="${DEPEND}
+		virtual/yacc"
+
+if [ "${EAPI:-0}" = "2" ]; then
+	DEPEND="${DEPEND} static? ( sys-libs/ncurses[static-libs] )"
+fi
+
 # compile-time-only
 mysql_version_is_at_least "5.1" \
 || DEPEND="${DEPEND} berkdb? ( sys-apps/ed )"
@@ -132,18 +162,46 @@
 mysql_version_is_at_least "5.1.12" \
 && DEPEND="${DEPEND} >=dev-util/cmake-2.4.3"
 
+[[ "${PN}" == "mariadb" ]] \
+&& mysql_version_is_at_least "5.2" \
+&& DEPEND="${DEPEND} oqgraph? ( >=dev-libs/boost-1.40.0 )"
+#SphinxSE is included but is not available in 5.2.4 due to a missing plug.in file
+#	sphinx? ( app-misc/sphinx )"
+
 # dev-perl/DBD-mysql is needed by some scripts installed by MySQL
 PDEPEND="perl? ( >=dev-perl/DBD-mysql-2.9004 )"
 
 # For other stuff to bring us in
-PDEPEND="${PDEPEND} =virtual/mysql-$(get_version_component_range 1-2 ${PV})"
+PDEPEND="${PDEPEND} =virtual/mysql-${MYSQL_PV_MAJOR}"
 
 # Work out the default SERVER_URI correctly
 if [ -z "${SERVER_URI}" ]; then
 	[ -z "${MY_PV}" ] && MY_PV="${PV//_/-}"
-	# The community build is on the mirrors
-	if [ "${MYSQL_COMMUNITY_FEATURES}" == "1" ]; then
-		SERVER_URI="mirror://mysql/Downloads/MySQL-${PV%.*}/mysql-${MY_PV}.tar.gz"
+	if [ "${PN}" == "mariadb" ]; then
+		MARIA_FULL_PV="$(replace_version_separator 3 '-' ${PV})"
+		MARIA_FULL_P="${PN}-${MARIA_FULL_PV}"
+		SERVER_URI="
+		http://ftp.osuosl.org/pub/mariadb/${MARIA_FULL_P}/kvm-tarbake-jaunty-x86/${MARIA_FULL_P}.tar.gz
+		http://ftp.rediris.es/mirror/MariaDB/${MARIA_FULL_P}/kvm-tarbake-jaunty-x86/${MARIA_FULL_P}.tar.gz
+		http://maria.llarian.net/download/${MARIA_FULL_P}/kvm-tarbake-jaunty-x86/${MARIA_FULL_P}.tar.gz
+		http://launchpad.net/maria/${MYSQL_PV_MAJOR}/ongoing/+download/${MARIA_FULL_P}.tar.gz
+		http://mirrors.fe.up.pt/pub/${PN}/${MARIA_FULL_P}/kvm-tarbake-jaunty-x86/${MARIA_FULL_P}.tar.gz
+		http://ftp-stud.hs-esslingen.de/pub/Mirrors/${PN}/${MARIA_FULL_P}/kvm-tarbake-jaunty-x86/${MARIA_FULL_P}.tar.gz
+		"
+	# The community and cluster builds are on the mirrors
+	elif [[ "${MYSQL_COMMUNITY_FEATURES}" == "1" || ${PN} == "mysql-cluster" ]] ; then
+		if [[ "${PN}" == "mysql-cluster" ]] ; then
+			URI_DIR="MySQL-Cluster"
+			URI_FILE="mysql-cluster-gpl"
+		else
+			URI_DIR="MySQL"
+			URI_FILE="mysql"
+		fi
+		URI_A="${URI_FILE}-${MY_PV}.tar.gz"
+		MIRROR_PV=$(get_version_component_range 1-2 ${PV})
+		# Recently upstream switched to an archive site, and not on mirrors
+		SERVER_URI="http://downloads.mysql.com/archives/${URI_FILE}-${MIRROR_PV}/${URI_A}
+					mirror://mysql/Downloads/${URI_DIR}-${PV%.*}/${URI_A}"
 	# The (old) enterprise source is on the primary site only
 	elif [ "${PN}" == "mysql" ]; then
 		SERVER_URI="ftp://ftp.mysql.com/pub/mysql/src/mysql-${MY_PV}.tar.gz"
@@ -162,6 +220,13 @@
 
 DESCRIPTION="A fast, multi-threaded, multi-user SQL database server."
 HOMEPAGE="http://www.mysql.com/"
+if [[ "${PN}" == "mariadb" ]]; then
+	HOMEPAGE="http://askmonty.org/"
+	DESCRIPTION="MariaDB is a MySQL fork with 3rd-party patches and additional storage engines merged."
+fi
+if [[ "${PN}" == "mysql-community" ]]; then
+	DESCRIPTION="${DESCRIPTION} (obsolete, move to dev-db/mysql)"
+fi
 LICENSE="GPL-2"
 SLOT="0"
 IUSE="big-tables debug embedded minimal ${IUSE_DEFAULT_ON}perl selinux ssl static test"
@@ -169,8 +234,12 @@
 mysql_version_is_at_least "4.1" \
 && IUSE="${IUSE} latin1"
 
-mysql_version_is_at_least "4.1.3" \
-&& IUSE="${IUSE} cluster extraengine"
+if mysql_version_is_at_least "4.1.3" ; then
+	IUSE="${IUSE} extraengine"
+	if [[ "${PN}" != "mysql-cluster" ]] ; then
+		IUSE="${IUSE} cluster"
+	fi
+fi
 
 mysql_version_is_at_least "5.0" \
 || IUSE="${IUSE} raid"
@@ -184,22 +253,63 @@
 [ "${MYSQL_COMMUNITY_FEATURES}" == "1" ] \
 && IUSE="${IUSE} ${IUSE_DEFAULT_ON}community profiling"
 
-# PBXT engine
-mysql_version_is_at_least "5.1.12" \
-&& [[ -n "${PBXT_VERSION}" ]] \
+[[ "${PN}" == "mariadb" ]] \
+&& IUSE="${IUSE} libevent"
+
+[[ "${PN}" == "mariadb" ]] \
+&& mysql_version_is_at_least "5.2" \
+&& IUSE="${IUSE} oqgraph"
+#SphinxSE is included but is not available in 5.2.4 due to a missing plug.in file
+#&& IUSE="${IUSE} oqgraph sphinx"
+
+# MariaDB has integrated PBXT
+# PBXT_VERSION means that we have a PBXT patch for this PV
+# PBXT was only introduced after 5.1.12
+pbxt_patch_available() {
+	[[ "${PN}" != "mariadb" ]] \
+	&& mysql_version_is_at_least "5.1.12" \
+	&& [[ -n "${PBXT_VERSION}" ]]
+	return $?
+}
+
+pbxt_available() {
+	pbxt_patch_available || [[ "${PN}" == "mariadb" ]]
+	return $?
+}
+
+# Get the percona tarball if XTRADB_VER and PERCONA_VER are both set
+# MariaDB has integrated XtraDB
+# XTRADB_VERS means that we have a XTRADB patch for this PV
+# XTRADB was only introduced after 5.1.26
+xtradb_patch_available() {
+	[[ "${PN}" != "mariadb" ]] \
+	&& mysql_version_is_at_least "5.1.26" \
+	&& [[ -n "${XTRADB_VER}" && -n "${PERCONA_VER}" ]]
+	return $?
+}
+
+
+pbxt_patch_available \
 && PBXT_P="pbxt-${PBXT_VERSION}" \
 && PBXT_SRC_URI="http://www.primebase.org/download/${PBXT_P}.tar.gz mirror://sourceforge/pbxt/${PBXT_P}.tar.gz" \
 && SRC_URI="${SRC_URI} pbxt? ( ${PBXT_SRC_URI} )" \
-&& IUSE="${IUSE} pbxt"
 
-# Get the percona tarball if XTRADB_VER and PERCONA_VER are both set
-mysql_version_is_at_least "5.1.26" \
-&& [[ -n "${XTRADB_VER}" && -n "${PERCONA_VER}" ]] \
+# PBXT_NEWSTYLE means pbxt is in storage/ and gets enabled as other plugins
+# vs. built outside the dir
+pbxt_available \
+&& IUSE="${IUSE} pbxt" \
+&& mysql_version_is_at_least "5.1.40" \
+&& PBXT_NEWSTYLE=1
+
+xtradb_patch_available \
 && XTRADB_P="percona-xtradb-${XTRADB_VER}" \
 && XTRADB_SRC_URI_COMMON="${PERCONA_VER}/source/${XTRADB_P}.tar.gz" \
-&& XTRADB_SRC_URI1="http://www.percona.com/percona-builds/xtradb/${XTRADB_SRC_URI_COMMON}" \
-&& XTRADB_SRC_URI2="http://www.percona.com/${PN}/xtradb/${XTRADB_SRC_URI_COMMON}" \
-&& SRC_URI="${SRC_URI} xtradb? ( ${XTRADB_SRC_URI1} ${XTRADB_SRC_URI2} )" \
+&& XTRADB_SRC_B1="http://www.percona.com/" \
+&& XTRADB_SRC_B2="${XTRADB_SRC_B1}/percona-builds/" \
+&& XTRADB_SRC_URI1="${XTRADB_SRC_B2}/Percona-Server/Percona-Server-${XTRADB_SRC_URI_COMMON}" \
+&& XTRADB_SRC_URI2="${XTRADB_SRC_B2}/xtradb/${XTRADB_SRC_URI_COMMON}" \
+&& XTRADB_SRC_URI3="${XTRADB_SRC_B1}/${PN}/xtradb/${XTRADB_SRC_URI_COMMON}" \
+&& SRC_URI="${SRC_URI} xtradb? ( ${XTRADB_SRC_URI1} ${XTRADB_SRC_URI2} ${XTRADB_SRC_URI3} )" \
 && IUSE="${IUSE} xtradb"
 
 #
@@ -214,7 +324,7 @@
 	rawtestname="${1}" ; shift
 	reason="${@}"
 	ewarn "test '${rawtestname}' disabled: '${reason}'"
-	
+
 	testsuite="${rawtestname/.*}"
 	testname="${rawtestname/*.}"
 	mysql_disable_file="${S}/mysql-test/t/disabled.def"
@@ -254,21 +364,21 @@
 # Initialize global variables
 # 2005-11-19 <vivo@gentoo.org>
 mysql_init_vars() {
-	MY_SHAREDSTATEDIR=${MY_SHAREDSTATEDIR="/usr/share/mysql"}
-	MY_SYSCONFDIR=${MY_SYSCONFDIR="/etc/mysql"}
-	MY_LIBDIR=${MY_LIBDIR="/usr/$(get_libdir)/mysql"}
-	MY_LOCALSTATEDIR=${MY_LOCALSTATEDIR="/var/lib/mysql"}
-	MY_LOGDIR=${MY_LOGDIR="/var/log/mysql"}
-	MY_INCLUDEDIR=${MY_INCLUDEDIR="/usr/include/mysql"}
+	MY_SHAREDSTATEDIR=${MY_SHAREDSTATEDIR="${EPREFIX}/usr/share/mysql"}
+	MY_SYSCONFDIR=${MY_SYSCONFDIR="${EPREFIX}/etc/mysql"}
+	MY_LIBDIR=${MY_LIBDIR="${EPREFIX}/usr/$(get_libdir)/mysql"}
+	MY_LOCALSTATEDIR=${MY_LOCALSTATEDIR="${EPREFIX}/var/lib/mysql"}
+	MY_LOGDIR=${MY_LOGDIR="${EPREFIX}/var/log/mysql"}
+	MY_INCLUDEDIR=${MY_INCLUDEDIR="${EPREFIX}/usr/include/mysql"}
 
 	if [[ -z "${MY_DATADIR}" ]] ; then
 		MY_DATADIR=""
-		if [[ -f "${MY_SYSCONFDIR}/my.cnf" ]] ; then
+		if [[ -f ${MY_SYSCONFDIR}/my.cnf ]] ; then
 			MY_DATADIR=`"my_print_defaults" mysqld 2>/dev/null \
 				| sed -ne '/datadir/s|^--datadir=||p' \
 				| tail -n1`
 			if [[ -z "${MY_DATADIR}" ]] ; then
-				MY_DATADIR=`grep ^datadir "${MY_SYSCONFDIR}/my.cnf" \
+				MY_DATADIR=`grep ^datadir ${MY_SYSCONFDIR}/my.cnf \
 				| sed -e 's/.*=\s*//' \
 				| tail -n1`
 			fi
@@ -306,8 +416,10 @@
 		fi
 	fi
 
-	MY_SOURCEDIR=${SERVER_URI##*/}
-	MY_SOURCEDIR=${MY_SOURCEDIR%.tar*}
+	if [ "${MY_SOURCEDIR:-unset}" == "unset" ]; then
+		MY_SOURCEDIR=${SERVER_URI##*/}
+		MY_SOURCEDIR=${MY_SOURCEDIR%.tar*}
+	fi
 
 	export MY_SHAREDSTATEDIR MY_SYSCONFDIR
 	export MY_LIBDIR MY_LOCALSTATEDIR MY_LOGDIR
@@ -348,7 +460,7 @@
 	myconf="${myconf} --with-extra-charsets=all"
 	myconf="${myconf} --with-mysqld-user=mysql"
 	myconf="${myconf} --with-server"
-	myconf="${myconf} --with-unix-socket-path=/var/run/mysqld/mysqld.sock"
+	myconf="${myconf} --with-unix-socket-path=${EPREFIX}/var/run/mysqld/mysqld.sock"
 	myconf="${myconf} --without-libwrap"
 
 	if use static ; then
@@ -364,7 +476,7 @@
 	else
 		myconf="${myconf} --without-debug"
 		mysql_version_is_at_least "4.1.3" \
-		&& use cluster \
+		&& ( use cluster || [[ "${PN}" == "mysql-cluster" ]] ) \
 		&& myconf="${myconf} --without-ndb-debug"
 	fi
 
@@ -393,12 +505,13 @@
 }
 
 configure_40_41_50() {
+	myconf="${myconf} --with-zlib-dir=${EPREFIX}/usr"
 	myconf="${myconf} $(use_with perl bench)"
 	myconf="${myconf} --enable-assembler"
 	myconf="${myconf} --with-extra-tools"
 	myconf="${myconf} --with-innodb"
 	myconf="${myconf} --without-readline"
-	myconf="${myconf} $(use_with ssl openssl)"
+	myconf="${myconf} $(use_with ssl openssl "${EPREFIX}/usr")"
 	mysql_version_is_at_least "5.0" || myconf="${myconf} $(use_with raid)"
 
 	# --with-vio is not needed anymore, it's on by default and
@@ -431,7 +544,9 @@
 
 	if mysql_version_is_at_least "4.1.3" ; then
 		myconf="${myconf} --with-geometry"
-		myconf="${myconf} $(use_with cluster ndbcluster)"
+		if [[ "${PN}" != "mysql-cluster" ]] ; then
+			myconf="${myconf} $(use_with cluster ndbcluster)"
+		fi
 	fi
 
 	if mysql_version_is_at_least "4.1.3" && use extraengine ; then
@@ -472,13 +587,18 @@
 	# TODO: !!!! readd --without-readline
 	# the failure depend upon config/ac-macros/readline.m4 checking into
 	# readline.h instead of history.h
-	myconf="${myconf} $(use_with ssl ssl /usr)"
+	myconf="${myconf} $(use_with ssl ssl "${EPREFIX}"/usr)"
 	myconf="${myconf} --enable-assembler"
 	myconf="${myconf} --with-geometry"
 	myconf="${myconf} --with-readline"
-	myconf="${myconf} --with-zlib-dir=/usr/"
+	myconf="${myconf} --with-zlib-dir=${EPREFIX}/usr/"
 	myconf="${myconf} --without-pstack"
-	use max-idx-128 && myconf="${myconf} --with-max-indexes=128"
+	myconf="${myconf} --with-plugindir=${EPREFIX}/usr/$(get_libdir)/mysql/plugin"
+
+	# This is an explict die here, because if we just forcibly disable it, then the
+	# user's data is not accessible.
+	use max-idx-128 && die "Bug #336027: upstream has a corruption issue with max-idx-128 presently"
+	#use max-idx-128 && myconf="${myconf} --with-max-indexes=128"
 	if [ "${MYSQL_COMMUNITY_FEATURES}" == "1" ]; then
 		myconf="${myconf} $(use_enable community community-features)"
 		if use community; then
@@ -488,47 +608,131 @@
 		fi
 	fi
 
+	# Scan for all available plugins
+	local plugins_avail="$(
+	LANG=C \
+	find "${S}" \
+		\( \
+		-name 'plug.in' \
+		-o -iname 'configure.in' \
+		-o -iname 'configure.ac' \
+		\) \
+		-print0 \
+	| xargs -0 sed -r -n \
+		-e '/^MYSQL_STORAGE_ENGINE/{
+			s~MYSQL_STORAGE_ENGINE\([[:space:]]*\[?([-_a-z0-9]+)\]?.*,~\1 ~g ;
+			s~^([^ ]+).*~\1~gp;
+		}' \
+	| tr -s '\n' ' '
+	)"
+
 	# 5.1 introduces a new way to manage storage engines (plugins)
 	# like configuration=none
-	local plugins="csv,myisam,myisammrg,heap"
+	# This base set are required, and will always be statically built.
+	local plugins_sta="csv myisam myisammrg heap"
+	local plugins_dyn=""
+	local plugins_dis="example ibmdb2i"
+
+	# These aren't actually required by the base set, but are really useful:
+	plugins_sta="${plugins_sta} archive blackhole"
+
+	# default in 5.5.4
+	if mysql_version_is_at_least "5.5.4" ; then
+		plugins_sta="${plugins_sta} partition"
+	fi
+	# Now the extras
 	if use extraengine ; then
 		# like configuration=max-no-ndb, archive and example removed in 5.1.11
 		# not added yet: ibmdb2i
-		# Not supporting as examples: example,daemon_example,ftexample 
-		plugins="${plugins},archive,blackhole,federated,partition"
+		# Not supporting as examples: example,daemon_example,ftexample
+		plugins_sta="${plugins_sta} partition"
 
-		elog "Before using the Federated storage engine, please be sure to read"
-		elog "http://dev.mysql.com/doc/refman/5.1/en/federated-limitations.html"
+		if [[ "${PN}" != "mariadb" ]] ; then
+			elog "Before using the Federated storage engine, please be sure to read"
+			elog "http://dev.mysql.com/doc/refman/5.1/en/federated-limitations.html"
+			plugins_dyn="${plugins_sta} federated"
+		else
+			elog "MariaDB includes the FederatedX engine. Be sure to read"
+			elog "http://askmonty.org/wiki/index.php/Manual:FederatedX_storage_engine"
+			plugins_dyn="${plugins_sta} federatedx"
+		fi
+	else
+		plugins_dis="${plugins_dis} partition federated"
 	fi
 
 	# Upstream specifically requests that InnoDB always be built:
 	# - innobase, innodb_plugin
 	# Build falcon if available for 6.x series.
-	for i in innobase innodb_plugin falcon ; do
-		[ -e "${S}"/storage/${i} ] && plugins="${plugins},${i}"
+	for i in innobase falcon ; do
+		[ -e "${S}"/storage/${i} ] && plugins_sta="${plugins_sta} ${i}"
+	done
+	for i in innodb_plugin ; do
+		[ -e "${S}"/storage/${i} ] && plugins_dyn="${plugins_dyn} ${i}"
 	done
 
 	# like configuration=max-no-ndb
-	if use cluster ; then
-		plugins="${plugins},ndbcluster"
+	if ( use cluster || [[ "${PN}" == "mysql-cluster" ]] ) ; then
+		plugins_sta="${plugins_sta} ndbcluster partition"
+		plugins_dis="${plugins_dis//partition}"
 		myconf="${myconf} --with-ndb-binlog"
+	else
+		plugins_dis="${plugins_dis} ndbcluster"
 	fi
 
-	myconf="${myconf} --with-plugins=${plugins}"
-}
+	if [[ "${PN}" == "mariadb" ]] ; then
+		# In MariaDB, InnoDB is packaged in the xtradb directory, so it's not
+		# caught above.
+		# This is not optional, without it several upstream testcases fail.
+		# Also strongly recommended by upstream.
+		if [[ "${PV}" < "5.2.0" ]] ; then
+			myconf="${myconf} --with-maria-tmp-tables"
+			plugins_sta="${plugins_sta} maria"
+		else
+			myconf="${myconf} --with-aria-tmp-tables"
+			plugins_sta="${plugins_sta} aria"
+		fi
 
-xtradb_applicable() {
-	mysql_version_is_at_least "5.1.26" \
-	&& [[ -n "${XTRADB_VER}" && -n "${PERCONA_VER}" ]] \
-	&& use xtradb
-	return $?
-}
+		[ -e "${S}"/storage/innobase ] || [ -e "${S}"/storage/xtradb ] ||
+			die "The ${P} package doesn't provide innobase nor xtradb"
 
-pbxt_applicable() {
-	mysql_version_is_at_least "5.1.12" \
-	&& [[ -n "${PBXT_VERSION}" ]] \
-	&& use pbxt
-	return $?
+		for i in innobase xtradb ; do
+			[ -e "${S}"/storage/${i} ] && plugins_sta="${plugins_sta} ${i}"
+		done
+
+		myconf="${myconf} $(use_with libevent)"
+
+		if mysql_version_is_at_least "5.2" ; then
+			#This should include sphinx, but the 5.2.4 archive forgot the plug.in file
+			#for i in oqgraph sphinx ; do
+			for i in oqgraph ; do
+				use ${i} \
+				&& plugins_dyn="${plugins_dyn} ${i}" \
+				|| plugins_dis="${plugins_dis} ${i}"
+			done
+		fi
+	fi
+
+	if pbxt_available && [[ "${PBXT_NEWSTYLE}" == "1" ]]; then
+		use pbxt \
+		&& plugins_sta="${plugins_sta} pbxt" \
+		|| plugins_dis="${plugins_dis} pbxt"
+	fi
+
+	use static && \
+	plugins_sta="${plugins_sta} ${plugins_dyn}" && \
+	plugins_dyn=""
+
+	einfo "Available plugins: ${plugins_avail}"
+	einfo "Dynamic plugins: ${plugins_dyn}"
+	einfo "Static plugins: ${plugins_sta}"
+	einfo "Disabled plugins: ${plugins_dis}"
+
+	# These are the static plugins
+	myconf="${myconf} --with-plugins=${plugins_sta// /,}"
+	# And the disabled ones
+	for i in ${plugins_dis} ; do
+		myconf="${myconf} --without-plugin-${i}"
+	done
 }
 
 pbxt_src_configure() {
@@ -537,16 +741,16 @@
 	pushd "${WORKDIR}/pbxt-${PBXT_VERSION}" &>/dev/null
 
 	einfo "Reconfiguring dir '${PWD}'"
-	AT_GNUCONF_UPDATE="yes" eautoreconf
+	eautoreconf
 
 	local myconf=""
-	myconf="${myconf} --with-mysql=${S} --libdir=${MY_LIBDIR}"
+	myconf="${myconf} --with-mysql=${S} --libdir=${EPREFIX}/usr/$(get_libdir)"
 	use debug && myconf="${myconf} --with-debug=full"
-	# TODO: is it safe/needed to use econf here ?
-	./configure ${myconf} || die "Problem configuring PBXT storage engine"
+	econf ${myconf} || die "Problem configuring PBXT storage engine"
 }
 
 pbxt_src_compile() {
+
 	# Be backwards compatible for now
 	if [[ $EAPI != 2 ]]; then
 		pbxt_src_configure
@@ -575,7 +779,7 @@
 #   create new user and group for mysql
 #   warn about deprecated features
 mysql_pkg_setup() {
-	if hasq test ${FEATURES} ; then
+	if has test ${FEATURES} ; then
 		if ! use minimal ; then
 			if [[ $UID -eq 0 ]]; then
 				eerror "Testing with FEATURES=-userpriv is no longer supported by upstream. Tests MUST be run as non-root."
@@ -583,10 +787,27 @@
 		fi
 	fi
 
+	# bug 350844
+	case "${EAPI:-0}" in
+		0 | 1)
+			if use static && ! built_with_use sys-libs/ncurses static-libs; then
+				die "To build MySQL statically you need to enable static-libs for sys-libs/ncurses"
+			fi
+			;;
+	esac
+
 	# Check for USE flag problems in pkg_setup
 	if use static && use ssl ; then
-		eerror "MySQL does not support being built statically with SSL support enabled!"
-		die "MySQL does not support being built statically with SSL support enabled!"
+		M="MySQL does not support being built statically with SSL support enabled!"
+		eerror "${M}"
+		die "${M}"
+	fi
+
+	if mysql_version_is_at_least "5.1.51" \
+	   && ! mysql_version_is_at_least "5.2" \
+	   && use debug ; then
+	   # Also in package.use.mask
+	   die "Bug #344885: Upstream has broken USE=debug for 5.1 series >=5.1.51"
 	fi
 
 	if ! mysql_version_is_at_least "5.0" \
@@ -598,17 +819,34 @@
 	fi
 
 	if mysql_version_is_at_least "4.1.3" \
-	&& ( use cluster || use extraengine ) \
+	&& ( use cluster || use extraengine || use embedded ) \
 	&& use minimal ; then
-		eerror "USE flags 'cluster' and 'extraengine' conflict with 'minimal' USE flag!"
-		die "USE flags 'cluster' and 'extraengine' conflict with 'minimal' USE flag!"
+		M="USE flags 'cluster', 'extraengine', 'embedded' conflict with 'minimal' USE flag!"
+		eerror "${M}"
+		die "${M}"
 	fi
 
-	# Bug #290570 fun. Upstream made us need a fairly new GCC4.
-	if mysql_version_is_at_least "5.0.83" ; then
+	if mysql_version_is_at_least "5.1" \
+	&& xtradb_patch_available \
+	&& use xtradb \
+	&& use embedded ; then
+		M="USE flags 'xtradb' and 'embedded' conflict and cause build failures"
+		eerror "${M}"
+		die "${M}"
+	fi
+
+	# Bug #290570, 284946, 307251
+	# Upstream changes made us need a fairly new GCC4.
+	# But only for 5.0.8[3-6]!
+	if mysql_version_is_at_least "5.0.83"  && ! mysql_version_is_at_least 5.0.87 ; then
 		GCC_VER=$(gcc-version)
-		case ${GCC_VER} in
-			2*|3*|4.0|4.1|4.2) die "Active GCC too old! Must have at least GCC4.3" ;;
+		case ${CHOST}:${GCC_VER} in
+			*-darwin*:4.*) : ;; # bug #310615
+			*:2*|*:3*|*:4.0|*:4.1|*:4.2)
+			eerror "Some releases of MySQL required a very new GCC, and then"
+			eerror "later release relaxed that requirement again. Either pick a"
+			eerror "MySQL >=5.0.87, or use a newer GCC."
+			die "Active GCC too old!" ;;
 		esac
 	fi
 
@@ -668,12 +906,15 @@
 	epatch
 
 	# last -fPIC fixup, per bug #305873
-	i="${S}"/storage/innodb_plugin/plug.in	
+	i="${S}"/storage/innodb_plugin/plug.in
 	[ -f "${i}" ] && sed -i -e '/CFLAGS/s,-prefer-non-pic,,g' "${i}"
 
-	# Additional checks, remove bundled zlib
-	rm -f "${S}/zlib/"*.[ch]
-	sed -i -e "s/zlib\/Makefile dnl/dnl zlib\/Makefile/" "${S}/configure.in"
+	# Additional checks, remove bundled zlib (Cluster needs this, for static
+	# memory management in zlib, leave available for Cluster)
+	if [[ "${PN}" != "mysql-cluster" ]] ; then
+		rm -f "${S}/zlib/"*.[ch]
+		sed -i -e "s/zlib\/Makefile dnl/dnl zlib\/Makefile/" "${S}/configure.in"
+	fi
 	rm -f "scripts/mysqlbug"
 
 	# Make charsets install in the right place
@@ -693,17 +934,26 @@
 
 	local rebuilddirlist d
 
-	if xtradb_applicable ; then
-		einfo "Replacing InnoDB with Percona XtraDB"
-		pushd "${S}"/storage
+	if xtradb_patch_available && use xtradb ; then
+		einfo "Adding storage engine: Percona XtraDB (replacing InnoDB)"
+		pushd "${S}"/storage >/dev/null
 		i="innobase"
 		o="${WORKDIR}/storage-${i}.mysql-upstream"
 		# Have we been here already?
 		[ -d "${o}" ] && rm -f "${i}"
 		# Or maybe we haven't
 		[ -d "${i}" -a ! -d "${o}" ] && mv "${i}" "${o}"
-		cp -ra "${WORKDIR}/${XTRADB_P}" "${i}"
-		popd
+		cp -ral "${WORKDIR}/${XTRADB_P}" "${i}"
+		popd >/dev/null
+	fi
+
+	if pbxt_patch_available && [[ "${PBXT_NEWSTYLE}" == "1" ]] && use pbxt ; then
+		einfo "Adding storage engine: PBXT"
+		pushd "${S}"/storage >/dev/null
+		i='pbxt'
+		[ -d "${i}" ] && rm -rf "${i}"
+		cp -ral "${WORKDIR}/${PBXT_P}" "${i}"
+		popd >/dev/null
 	fi
 
 	if mysql_version_is_at_least "5.1.12" ; then
@@ -722,7 +972,7 @@
 	for d in ${rebuilddirlist} ; do
 		einfo "Reconfiguring dir '${d}'"
 		pushd "${d}" &>/dev/null
-		AT_GNUCONF_UPDATE="yes" eautoreconf
+		eautoreconf
 		popd &>/dev/null
 	done
 
@@ -730,14 +980,14 @@
 	&& use berkdb ; then
 		einfo "Fixing up berkdb buildsystem"
 		[[ -w "bdb/dist/ltmain.sh" ]] && cp -f "ltmain.sh" "bdb/dist/ltmain.sh"
-		cp -f "/usr/share/aclocal/libtool.m4" "bdb/dist/aclocal/libtool.ac" \
+		cp -f "${EPREFIX}/usr/share/aclocal/libtool.m4" "bdb/dist/aclocal/libtool.ac" \
 		|| die "Could not copy libtool.m4 to bdb/dist/"
 		#These files exist only with libtool-2*, and need to be included.
-		if [ -f '/usr/share/aclocal/ltsugar.m4' ]; then
-			cat "/usr/share/aclocal/ltsugar.m4" >>  "bdb/dist/aclocal/libtool.ac"
-			cat "/usr/share/aclocal/ltversion.m4" >>  "bdb/dist/aclocal/libtool.ac"
-			cat "/usr/share/aclocal/lt~obsolete.m4" >>  "bdb/dist/aclocal/libtool.ac"
-			cat "/usr/share/aclocal/ltoptions.m4" >>  "bdb/dist/aclocal/libtool.ac"
+		if [ -f ${EPREFIX}'/usr/share/aclocal/ltsugar.m4' ]; then
+			cat "${EPREFIX}/usr/share/aclocal/ltsugar.m4" >>  "bdb/dist/aclocal/libtool.ac"
+			cat "${EPREFIX}/usr/share/aclocal/ltversion.m4" >>  "bdb/dist/aclocal/libtool.ac"
+			cat "${EPREFIX}/usr/share/aclocal/lt~obsolete.m4" >>  "bdb/dist/aclocal/libtool.ac"
+			cat "${EPREFIX}/usr/share/aclocal/ltoptions.m4" >>  "bdb/dist/aclocal/libtool.ac"
 		fi
 		pushd "bdb/dist" &>/dev/null
 		sh s_all \
@@ -771,7 +1021,7 @@
 	filter-flags "-O" "-O[01]"
 
 	# glib-2.3.2_pre fix, bug #16496
-	append-flags "-DHAVE_ERRNO_AS_DEFINE=1"
+	append-cppflags "-DHAVE_ERRNO_AS_DEFINE=1"
 
 	# As discovered by bug #246652, doing a double-level of SSP causes NDB to
 	# fail badly during cluster startup.
@@ -788,18 +1038,28 @@
 	# bug #283926, with GCC4.4, this is required to get correct behavior.
 	append-flags -fno-strict-aliasing
 
+	# bug #335185, #335995, with >= GCC4.3.3 on x86 only, omit-frame-pointer
+	# causes a mis-compile.
+	# Upstream bugs:
+	# http://gcc.gnu.org/bugzilla/show_bug.cgi?id=38562
+	# http://bugs.mysql.com/bug.php?id=45205
+	use x86 && version_is_at_least "4.3.3" "$(gcc-fullversion)" && \
+		append-flags -fno-omit-frame-pointer && \
+		filter-flags -fomit-frame-pointer
+
 	econf \
-		--libexecdir="/usr/sbin" \
-		--sysconfdir="${MY_SYSCONFDIR}" \
-		--localstatedir="${MY_LOCALSTATEDIR}" \
-		--sharedstatedir="${MY_SHAREDSTATEDIR}" \
-		--libdir="${MY_LIBDIR}" \
-		--includedir="${MY_INCLUDEDIR}" \
+		--libexecdir="${EPREFIX}"/usr/sbin \
+		--sysconfdir=${MY_SYSCONFDIR} \
+		--localstatedir=${MY_LOCALSTATEDIR} \
+		--sharedstatedir=${MY_SHAREDSTATEDIR} \
+		--libdir=${MY_LIBDIR} \
+		--includedir=${MY_INCLUDEDIR} \
 		--with-low-memory \
 		--with-client-ldflags=-lstdc++ \
 		--enable-thread-safe-client \
 		--with-comment="Gentoo Linux ${PF}" \
 		--without-docs \
+		--with-LIBDIR="$(get_libdir)" \
 		${myconf} || die "econf failed"
 
 	# TODO: Move this before autoreconf !!!
@@ -807,8 +1067,8 @@
 	| xargs -0 -n100 sed -i \
 	-e 's|^pkglibdir *= *$(libdir)/mysql|pkglibdir = $(libdir)|;s|^pkgincludedir *= *$(includedir)/mysql|pkgincludedir = $(includedir)|'
 
-	if [[ $EAPI == 2 ]]; then
-		pbxt_applicable && pbxt_src_configure
+	if [[ $EAPI == 2 ]] && [[ "${PBXT_NEWSTYLE}" != "1" ]]; then
+		pbxt_patch_available && use pbxt && pbxt_src_configure
 	fi
 }
 
@@ -817,14 +1077,16 @@
 # Compile the mysql code.
 mysql_src_compile() {
 	# Be backwards compatible for now
-        case ${EAPI:-0} in
-                2) : ;;
-                0 | 1) mysql_src_configure ;;
-        esac
+	case ${EAPI:-0} in
+		2) : ;;
+		0 | 1) mysql_src_configure ;;
+	esac
 
 	emake || die "emake failed"
 
-	pbxt_applicable && pbxt_src_compile
+	if [[ "${PBXT_NEWSTYLE}" != "1" ]]; then
+		pbxt_patch_available && use pbxt && pbxt_src_compile
+	fi
 }
 
 # @FUNCTION: mysql_src_install
@@ -836,11 +1098,13 @@
 
 	emake install \
 		DESTDIR="${D}" \
-		benchdir_root="${MY_SHAREDSTATEDIR}" \
+		benchdir_root=${MY_SHAREDSTATEDIR} \
 		testroot="${MY_SHAREDSTATEDIR}" \
 		|| die "emake install failed"
 
-	pbxt_applicable && pbxt_src_install
+	if [[ "${PBXT_NEWSTYLE}" != "1" ]]; then
+		pbxt_patch_available && use pbxt && pbxt_src_install
+	fi
 
 	# Convenience links
 	einfo "Making Convenience links for mysqlcheck multi-call binary"
@@ -850,7 +1114,7 @@
 
 	# Various junk (my-*.cnf moved elsewhere)
 	einfo "Removing duplicate /usr/share/mysql files"
-	rm -Rf "${D}/usr/share/info"
+	rm -Rf "${ED}/usr/share/info"
 	for removeme in  "mysql-log-rotate" mysql.server* \
 		binary-configure* my-*.cnf mi_test_all*
 	do
@@ -861,8 +1125,8 @@
 	if use minimal ; then
 		einfo "Remove all extra content for minimal build"
 		rm -Rf "${D}${MY_SHAREDSTATEDIR}"/{mysql-test,sql-bench}
-		rm -f "${D}"/usr/bin/{mysql{_install_db,manager*,_secure_installation,_fix_privilege_tables,hotcopy,_convert_table_format,d_multi,_fix_extensions,_zap,_explain_log,_tableinfo,d_safe,_install,_waitpid,binlog,test},myisam*,isam*,pack_isam}
-		rm -f "${D}/usr/sbin/mysqld"
+		rm -f "${ED}"/usr/bin/{mysql{_install_db,manager*,_secure_installation,_fix_privilege_tables,hotcopy,_convert_table_format,d_multi,_fix_extensions,_zap,_explain_log,_tableinfo,d_safe,_install,_waitpid,binlog,test},myisam*,isam*,pack_isam}
+		rm -f "${ED}/usr/sbin/mysqld"
 		rm -f "${D}${MY_LIBDIR}"/lib{heap,merge,nisam,my{sys,strings,sqld,isammrg,isam},vio,dbug}.a
 	fi
 
@@ -874,19 +1138,26 @@
 	fi
 
 	# Configuration stuff
-	if mysql_version_is_at_least "4.1" ; then
-		mysql_mycnf_version="4.1"
-	else
-		mysql_mycnf_version="4.0"
-	fi
-	einfo "Building default my.cnf"
-	insinto "${MY_SYSCONFDIR}"
+	case ${MYSQL_PV_MAJOR} in
+		3*|4.0) mysql_mycnf_version="4.0" ;;
+		4.[1-9]|5.0) mysql_mycnf_version="4.1" ;;
+		5.[1-9]|6*|7*) mysql_mycnf_version="5.1" ;;
+	esac
+	einfo "Building default my.cnf (${mysql_mycnf_version})"
+	insinto "${MY_SYSCONFDIR#${EPREFIX}}"
 	doins scripts/mysqlaccess.conf
+	mycnf_src="my.cnf-${mysql_mycnf_version}"
 	sed -e "s!@DATADIR@!${MY_DATADIR}!g" \
-		"${FILESDIR}/my.cnf-${mysql_mycnf_version}" \
+		-e "s!/tmp!${EPREFIX}/tmp!" \
+		-e "s!/usr!${EPREFIX}/usr!" \
+		-e "s!= /var!= ${EPREFIX}/var!" \
+		"${FILESDIR}/${mycnf_src}" \
 		> "${TMPDIR}/my.cnf.ok"
-	if mysql_version_is_at_least "4.1" && use latin1 ; then
-		sed -e "s|utf8|latin1|g" -i "${TMPDIR}/my.cnf.ok"
+	use prefix && sed -i -e '/^user[ 	]*= mysql$/d' "${TMPDIR}/my.cnf.ok"
+	if use latin1 ; then
+		sed -i \
+			-e "/character-set/s|utf8|latin1|g" \
+			"${TMPDIR}/my.cnf.ok"
 	fi
 	newins "${TMPDIR}/my.cnf.ok" my.cnf
 
@@ -896,22 +1167,24 @@
 		# Empty directories ...
 		diropts "-m0750"
 		if [[ "${PREVIOUS_DATADIR}" != "yes" ]] ; then
-			dodir "${MY_DATADIR}"
-			keepdir "${MY_DATADIR}"
+			dodir "${MY_DATADIR#${EPREFIX}}"
+			keepdir "${MY_DATADIR#${EPREFIX}}"
 			chown -R mysql:mysql "${D}/${MY_DATADIR}"
 		fi
 
 		diropts "-m0755"
-		for folder in "${MY_LOGDIR}" "/var/run/mysqld" ; do
+		for folder in "${MY_LOGDIR#${EPREFIX}}" "/var/run/mysqld" ; do
 			dodir "${folder}"
 			keepdir "${folder}"
-			chown -R mysql:mysql "${D}/${folder}"
+			chown -R mysql:mysql "${ED}/${folder}"
 		done
 	fi
 
 	# Docs
 	einfo "Installing docs"
-	dodoc README ChangeLog EXCEPTIONS-CLIENT INSTALL-SOURCE
+	for i in README ChangeLog EXCEPTIONS-CLIENT INSTALL-SOURCE ; do
+		[[ -f "$i" ]] && dodoc "$i"
+	done
 	doinfo "${S}"/Docs/mysql.info
 
 	# Minimal builds don't have the MySQL server
@@ -933,7 +1206,7 @@
 
 	fi
 
-	mysql_lib_symlinks "${D}"
+	mysql_lib_symlinks "${ED}"
 }
 
 # @FUNCTION: mysql_pkg_preinst
@@ -957,7 +1230,7 @@
 	mysql_init_vars
 
 	# Check FEATURES="collision-protect" before removing this
-	[[ -d "${ROOT}/var/log/mysql" ]] || install -d -m0750 -o mysql -g mysql "${ROOT}${MY_LOGDIR}"
+	[[ -d "${EROOT}/var/log/mysql" ]] || install -d -m0750 -o mysql -g mysql "${ROOT}${MY_LOGDIR}"
 
 	# Secure the logfiles
 	touch "${ROOT}${MY_LOGDIR}"/mysql.{log,err}
@@ -972,12 +1245,15 @@
 			support-files/magic \
 			support-files/ndb-config-2-node.ini
 		do
-			dodoc "${script}"
+			[[ -f "${script}" ]] \
+			&& dodoc "${script}"
 		done
 
 		docinto "scripts"
 		for script in scripts/mysql* ; do
-			[[ "${script%.sh}" == "${script}" ]] && dodoc "${script}"
+			[[ -f "${script}" ]] \
+			&& [[ "${script%.sh}" == "${script}" ]] \
+			&& dodoc "${script}"
 		done
 
 		einfo
@@ -985,13 +1261,18 @@
 		elog "\"emerge --config =${CATEGORY}/${PF}\""
 		elog "if this is a new install."
 		einfo
+
+		einfo
+		elog "If you are upgrading major versions, you should run the"
+		elog "mysql_upgrade tool."
+		einfo
 	fi
 
-	if pbxt_applicable ; then
-		# TODO: explain it better
-		elog "    mysql> INSTALL PLUGIN pbxt SONAME 'libpbxt.so';"
-		elog "    mysql> CREATE TABLE t1 (c1 int, c2 text) ENGINE=pbxt;"
-		elog "if, after that, you cannot start the MySQL server,"
+	if pbxt_available && use pbxt ; then
+                elog "Note: PBXT is now statically built when enabled."
+                elog ""
+                elog "If, you previously installed as a plugin and "
+                elog "you cannot start the MySQL server,"
 		elog "remove the ${MY_DATADIR}/mysql/plugin.* files, then"
 		elog "use the MySQL upgrade script to restore the table"
 		elog "or execute the following SQL command:"
@@ -1007,11 +1288,34 @@
 	&& elog "Berkeley DB support is deprecated and will be removed in future versions!"
 }
 
+# @FUNCTION: mysql_getopt
+# @DESCRIPTION:
+# Use my_print_defaults to extract specific config options
+mysql_getopt() {
+	local mypd="${EROOT}"/usr/bin/my_print_defaults
+	section="$1"
+	flag="--${2}="
+	"${mypd}" $section | sed -n "/^${flag}/p"
+}
+
+# @FUNCTION: mysql_getoptval
+# @DESCRIPTION:
+# Use my_print_defaults to extract specific config options
+mysql_getoptval() {
+	local mypd="${EROOT}"/usr/bin/my_print_defaults
+	section="$1"
+	flag="--${2}="
+	"${mypd}" $section | sed -n "/^${flag}/s,${flag},,gp"
+}
+
 # @FUNCTION: mysql_pkg_config
 # @DESCRIPTION:
 # Configure mysql environment.
 mysql_pkg_config() {
 	local old_MY_DATADIR="${MY_DATADIR}"
+	local old_HOME="${HOME}"
+	# my_print_defaults needs to read stuff in $HOME/.my.cnf
+	export HOME=/root
 
 	# Make sure the vars are correctly initialized
 	mysql_init_vars
@@ -1023,10 +1327,12 @@
 	fi
 
 	if [[ ( -n "${MY_DATADIR}" ) && ( "${MY_DATADIR}" != "${old_MY_DATADIR}" ) ]]; then
-		local MY_DATADIR_s="$(strip_duplicate_slashes ${ROOT}/${MY_DATADIR})"
-		local old_MY_DATADIR_s="$(strip_duplicate_slashes ${ROOT}/${old_MY_DATADIR})"
+		local MY_DATADIR_s="${ROOT}/${MY_DATADIR}"
+		MY_DATADIR_s="${MY_DATADIR_s%%/}"
+		local old_MY_DATADIR_s="${ROOT}/${old_MY_DATADIR}"
+		old_MY_DATADIR_s="${old_MY_DATADIR_s%%/}"
 
-		if [[ -d "${old_MY_DATADIR_s}" ]]; then
+		if [[ -d "${old_MY_DATADIR_s}" ]]  && [[ "${old_MY_DATADIR_s}" != / ]]; then
 			if [[ -d "${MY_DATADIR_s}" ]]; then
 				ewarn "Both ${old_MY_DATADIR_s} and ${MY_DATADIR_s} exist"
 				ewarn "Attempting to use ${MY_DATADIR_s} and preserving ${old_MY_DATADIR_s}"
@@ -1048,7 +1354,30 @@
 
 	local pwd1="a"
 	local pwd2="b"
-	local maxtry=5
+	local maxtry=15
+
+	if [ -z "${MYSQL_ROOT_PASSWORD}" ]; then
+		MYSQL_ROOT_PASSWORD="$(mysql_getoptval 'client mysql' password)"
+	fi
+	MYSQL_TMPDIR="$(mysql_getoptval mysqld tmpdir)"
+	# These are dir+prefix
+	MYSQL_RELAY_LOG="$(mysql_getoptval mysqld relay-log)"
+	MYSQL_RELAY_LOG=${MYSQL_RELAY_LOG%/*}
+	MYSQL_LOG_BIN="$(mysql_getoptval mysqld log-bin)"
+	MYSQL_LOG_BIN=${MYSQL_LOG_BIN%/*}
+
+	if [[ ! -d "${EROOT}"/$MYSQL_TMPDIR ]]; then
+		einfo "Creating MySQL tmpdir $MYSQL_TMPDIR"
+		install -d -m 770 -o mysql -g mysql "${EROOT}"/$MYSQL_TMPDIR
+	fi
+	if [[ ! -d "${EROOT}"/$MYSQL_LOG_BIN ]]; then
+		einfo "Creating MySQL log-bin directory $MYSQL_LOG_BIN"
+		install -d -m 770 -o mysql -g mysql "${EROOT}"/$MYSQL_LOG_BIN
+	fi
+	if [[ ! -d "${EROOT}"/$MYSQL_RELAY_LOG ]]; then
+		einfo "Creating MySQL relay-log directory $MYSQL_RELAY_LOG"
+		install -d -m 770 -o mysql -g mysql "${EROOT}"/$MYSQL_RELAY_LOG
+	fi
 
 	if [[ -d "${ROOT}/${MY_DATADIR}/mysql" ]] ; then
 		ewarn "You have already a MySQL database in place."
@@ -1061,21 +1390,24 @@
 	# localhost. Also causes weird failures.
 	[[ "${HOSTNAME}" == "localhost" ]] && die "Your machine must NOT be named localhost"
 
-	einfo "Creating the mysql database and setting proper"
-	einfo "permissions on it ..."
+	if [ -z "${MYSQL_ROOT_PASSWORD}" ]; then
 
-	einfo "Insert a password for the mysql 'root' user"
-	ewarn "Avoid [\"'\\_%] characters in the password"
-	read -rsp "    >" pwd1 ; echo
+		einfo "Please provide a password for the mysql 'root' user now, in the"
+		einfo "MYSQL_ROOT_PASSWORD env var or through the /root/.my.cnf file."
+		ewarn "Avoid [\"'\\_%] characters in the password"
+		read -rsp "    >" pwd1 ; echo
 
-	einfo "Retype the password"
-	read -rsp "    >" pwd2 ; echo
+		einfo "Retype the password"
+		read -rsp "    >" pwd2 ; echo
 
-	if [[ "x$pwd1" != "x$pwd2" ]] ; then
-		die "Passwords are not the same"
+		if [[ "x$pwd1" != "x$pwd2" ]] ; then
+			die "Passwords are not the same"
+		fi
+		MYSQL_ROOT_PASSWORD="${pwd1}"
+		unset pwd1 pwd2
 	fi
 
-	local options=""
+	local options="--log-warnings=0"
 	local sqltmp="$(emktemp)"
 
 	local help_tables="${ROOT}${MY_SHAREDSTATEDIR}/fill_help_tables.sql"
@@ -1084,11 +1416,33 @@
 	|| touch "${TMPDIR}/fill_help_tables.sql"
 	help_tables="${TMPDIR}/fill_help_tables.sql"
 
+	# Figure out which options we need to disable to do the setup
+	helpfile="${TMPDIR}/mysqld-help"
+	${EROOT}/usr/sbin/mysqld --verbose --help >"${helpfile}" 2>/dev/null
+	for opt in grant-tables host-cache name-resolve networking slave-start bdb \
+		federated innodb ssl log-bin relay-log slow-query-log external-locking \
+		ndbcluster log-slave-updates \
+		; do
+		optexp="--(skip-)?${opt}" optfull="--loose-skip-${opt}"
+		egrep -sq -- "${optexp}" "${helpfile}" && options="${options} ${optfull}"
+	done
+	# But some options changed names
+	egrep -sq external-locking "${helpfile}" && \
+	options="${options/skip-locking/skip-external-locking}"
+
+	use prefix || options="${options} --user=mysql"
+
 	pushd "${TMPDIR}" &>/dev/null
-	"${ROOT}/usr/bin/mysql_install_db" >"${TMPDIR}"/mysql_install_db.log 2>&1
+	#cmd="'${EROOT}/usr/share/mysql/scripts/mysql_install_db' '--basedir=${EPREFIX}/usr' ${options}"
+	cmd=${EROOT}usr/share/mysql/scripts/mysql_install_db
+	[ -f ${cmd} ] || cmd=${EROOT}usr/bin/mysql_install_db
+	cmd="'$cmd' '--basedir=${EPREFIX}/usr' ${options}"
+	einfo "Command: $cmd"
+	eval $cmd \
+		>"${TMPDIR}"/mysql_install_db.log 2>&1
 	if [ $? -ne 0 ]; then
 		grep -B5 -A999 -i "ERROR" "${TMPDIR}"/mysql_install_db.log 1>&2
-		die "Failed to run mysql_install_db. Please review /var/log/mysql/mysqld.err AND ${TMPDIR}/mysql_install_db.log"
+		die "Failed to run mysql_install_db. Please review ${EPREFIX}/var/log/mysql/mysqld.err AND ${TMPDIR}/mysql_install_db.log"
 	fi
 	popd &>/dev/null
 	[[ -f "${ROOT}/${MY_DATADIR}/mysql/user.frm" ]] \
@@ -1097,59 +1451,71 @@
 	chmod 0750 "${ROOT}/${MY_DATADIR}" 2>/dev/null
 
 	if mysql_version_is_at_least "4.1.3" ; then
-		options="--skip-ndbcluster"
-
 		# Filling timezones, see
 		# http://dev.mysql.com/doc/mysql/en/time-zone-support.html
-		"${ROOT}/usr/bin/mysql_tzinfo_to_sql" "${ROOT}/usr/share/zoneinfo" > "${sqltmp}" 2>/dev/null
+		"${EROOT}/usr/bin/mysql_tzinfo_to_sql" "${EROOT}/usr/share/zoneinfo" > "${sqltmp}" 2>/dev/null
 
 		if [[ -r "${help_tables}" ]] ; then
 			cat "${help_tables}" >> "${sqltmp}"
 		fi
 	fi
 
-	local socket="${ROOT}/var/run/mysqld/mysqld${RANDOM}.sock"
-	local pidfile="${ROOT}/var/run/mysqld/mysqld${RANDOM}.pid"
-	local mysqld="${ROOT}/usr/sbin/mysqld \
+	einfo "Creating the mysql database and setting proper"
+	einfo "permissions on it ..."
+
+	local socket="${EROOT}/var/run/mysqld/mysqld${RANDOM}.sock"
+	local pidfile="${EROOT}/var/run/mysqld/mysqld${RANDOM}.pid"
+	local mysqld="${EROOT}/usr/sbin/mysqld \
 		${options} \
 		--user=mysql \
-		--skip-grant-tables \
-		--basedir=${ROOT}/usr \
+		--log-warnings=0 \
+		--basedir=${EROOT}/usr \
 		--datadir=${ROOT}/${MY_DATADIR} \
-		--skip-innodb \
-		--skip-bdb \
-		--skip-networking \
 		--max_allowed_packet=8M \
 		--net_buffer_length=16K \
+		--default-storage-engine=MyISAM \
 		--socket=${socket} \
 		--pid-file=${pidfile}"
+	#einfo "About to start mysqld: ${mysqld}"
+	ebegin "Starting mysqld"
+	einfo "Command ${mysqld}"
 	${mysqld} &
+	rc=$?
 	while ! [[ -S "${socket}" || "${maxtry}" -lt 1 ]] ; do
 		maxtry=$((${maxtry}-1))
 		echo -n "."
 		sleep 1
 	done
+	eend $rc
 
+	if ! [[ -S "${socket}" ]]; then
+		die "Completely failed to start up mysqld with: ${mysqld}"
+	fi
+
+	ebegin "Setting root password"
 	# Do this from memory, as we don't want clear text passwords in temp files
-	local sql="UPDATE mysql.user SET Password = PASSWORD('${pwd1}') WHERE USER='root'"
-	"${ROOT}/usr/bin/mysql" \
+	local sql="UPDATE mysql.user SET Password = PASSWORD('${MYSQL_ROOT_PASSWORD}') WHERE USER='root'"
+	"${EROOT}/usr/bin/mysql" \
 		--socket=${socket} \
 		-hlocalhost \
 		-e "${sql}"
+	eend $?
 
-	einfo "Loading \"zoneinfo\", this step may require a few seconds ..."
-
-	"${ROOT}/usr/bin/mysql" \
+	ebegin "Loading \"zoneinfo\", this step may require a few seconds ..."
+	"${EROOT}/usr/bin/mysql" \
 		--socket=${socket} \
 		-hlocalhost \
 		-uroot \
-		-p"${pwd1}" \
+		--password="${MYSQL_ROOT_PASSWORD}" \
 		mysql < "${sqltmp}"
+	rc=$?
+	eend $?
+	[ $rc -ne 0 ] && ewarn "Failed to load zoneinfo!"
 
 	# Stop the server and cleanup
+	einfo "Stopping the server ..."
 	kill $(< "${pidfile}" )
 	rm -f "${sqltmp}"
-	einfo "Stopping the server ..."
 	wait %1
 	einfo "Done"
 }
@@ -1158,5 +1524,5 @@
 # @DESCRIPTION:
 # Remove mysql symlinks.
 mysql_pkg_postrm() {
-	: # mysql_lib_symlinks "${D}"
+	: # mysql_lib_symlinks "${ED}"
 }
diff --git a/eclass/mysql_fx.eclass b/eclass/mysql_fx.eclass
index 2ee1100..2e56fba 100644
--- a/eclass/mysql_fx.eclass
+++ b/eclass/mysql_fx.eclass
@@ -1,9 +1,11 @@
-# Copyright 1999-2007 Gentoo Foundation
+# Copyright 1999-2012 Gentoo Foundation
 # Distributed under the terms of the GNU General Public License v2
-# $Header: /var/cvsroot/gentoo-x86/eclass/mysql_fx.eclass,v 1.22 2009/02/12 05:05:14 robbat2 Exp $
+# $Header: /var/cvsroot/gentoo-x86/eclass/mysql_fx.eclass,v 1.30 2012/01/09 10:42:19 grobian Exp $
 
 # Author: Francesco Riosa (Retired) <vivo@gentoo.org>
-# Maintainer: Luca Longinotti <chtekk@gentoo.org>
+# Maintainer:
+#	- MySQL Team <mysql-bugs@gentoo.org>
+#	- Luca Longinotti <chtekk@gentoo.org>
 
 inherit multilib
 
@@ -182,30 +184,122 @@
 # library to the best version available.
 #
 mysql_lib_symlinks() {
-	einfo "Updating MySQL .so symlinks"
-	local d dirlist maxdots soname sonameln reldir
+
+	local d dirlist maxdots libname libnameln libsuffix reldir
+	libsuffix=$(get_libname)
+
+	einfo "libsuffix = ${libsuffix}"
+	einfo "Updating MySQL libraries symlinks"
+
 	reldir="${1}"
 	pushd "${reldir}/usr/$(get_libdir)" &> /dev/null
-		# dirlist must contain the less significative directory left
-		dirlist="mysql"
 
-		# waste some time in removing and recreating symlinks
-		for d in $dirlist ; do
-			for soname in $( find "${d}" -name "*.so*" -and -not -type "l" 2>/dev/null ) ; do
-				# maxdot is a limit versus infinite loop
-				maxdots=0
-				sonameln=${soname##*/}
-				# loop in version of the library to link it, similar to how
-				# libtool works
-				while [[ ${sonameln:0-3} != '.so' ]] && [[ ${maxdots} -lt 6 ]] ; do
-					rm -f "${sonameln}"
-					ln -s "${soname}" "${sonameln}"
+	# dirlist must contain the less significative directory left
+	dirlist="mysql"
+
+	# waste some time in removing and recreating symlinks
+	for d in $dirlist ; do
+		for libname in $( find "${d}" -mindepth 1 -maxdepth 1 -name "*${libsuffix}*" -and -not -type "l" 2>/dev/null ) ; do
+			# maxdot is a limit versus infinite loop
+			maxdots=0
+			libnameln=${libname##*/}
+			# loop in version of the library to link it, similar to how
+			# libtool works
+			if [[ ${CHOST} == *-darwin* ]] ; then
+				# macho: libname.x.y.z.dylib
+				local libbasename=${libnameln%%.*}       # libname
+				local libver=${libnameln#${libbasename}} # .x.y.z.dylib
+				libver=${libver%${libsuffix}}            # .x.y.z
+				while [[ -n ${libver} ]] && [[ ${maxdots} -lt 6 ]] ; do
+					libnameln="${libbasename}${libver}${libsuffix}"
+					rm -f "${libnameln}"
+					ln -s "${libname}" "${libnameln}"
 					(( ++maxdots ))
-					sonameln="${sonameln%.*}"
+					libver=${libver%.*}
 				done
-				rm -f "${sonameln}"
-				ln -s "${soname}" "${sonameln}"
-			done
+				libnameln="${libbasename}${libsuffix}"
+				rm -f "${libnameln}"
+				ln -s "${libname}" "${libnameln}"
+			else
+				# elf: libname.so.x.y.z
+				while [[ ${libnameln:0-3} != '${libsuffix}' ]] && [[ ${maxdots} -lt 6 ]] ; do
+					rm -f "${libnameln}"
+					ln -s "${libname}" "${libnameln}"
+					(( ++maxdots ))
+					libnameln="${libnameln%.*}"
+				done
+				rm -f "${libnameln}"
+				ln -s "${libname}" "${libnameln}"
+			fi
 		done
+	done
+
 	popd &> /dev/null
 }
+
+# @FUNCTION: mysql_init_vars
+# @DESCRIPTION:
+# void mysql_init_vars()
+# Initialize global variables
+# 2005-11-19 <vivo@gentoo.org>
+mysql_init_vars() {
+	MY_SHAREDSTATEDIR=${MY_SHAREDSTATEDIR="${EPREFIX}/usr/share/mysql"}
+	MY_SYSCONFDIR=${MY_SYSCONFDIR="${EPREFIX}/etc/mysql"}
+	MY_LOCALSTATEDIR=${MY_LOCALSTATEDIR="${EPREFIX}/var/lib/mysql"}
+	MY_LOGDIR=${MY_LOGDIR="${EPREFIX}/var/log/mysql"}
+	MY_INCLUDEDIR=${MY_INCLUDEDIR="${EPREFIX}/usr/include/mysql"}
+	MY_LIBDIR=${MY_LIBDIR="${EPREFIX}/usr/$(get_libdir)/mysql"}
+
+	if [[ -z "${MY_DATADIR}" ]] ; then
+		MY_DATADIR=""
+		if [[ -f "${MY_SYSCONFDIR}/my.cnf" ]] ; then
+			MY_DATADIR=`"my_print_defaults" mysqld 2>/dev/null \
+				| sed -ne '/datadir/s|^--datadir=||p' \
+				| tail -n1`
+			if [[ -z "${MY_DATADIR}" ]] ; then
+				MY_DATADIR=`grep ^datadir "${MY_SYSCONFDIR}/my.cnf" \
+				| sed -e 's/.*=\s*//' \
+				| tail -n1`
+			fi
+		fi
+		if [[ -z "${MY_DATADIR}" ]] ; then
+			MY_DATADIR="${MY_LOCALSTATEDIR}"
+			einfo "Using default MY_DATADIR"
+		fi
+		elog "MySQL MY_DATADIR is ${MY_DATADIR}"
+
+		if [[ -z "${PREVIOUS_DATADIR}" ]] ; then
+			if [[ -e "${MY_DATADIR}" ]] ; then
+				# If you get this and you're wondering about it, see bug #207636
+				elog "MySQL datadir found in ${MY_DATADIR}"
+				elog "A new one will not be created."
+				PREVIOUS_DATADIR="yes"
+			else
+				PREVIOUS_DATADIR="no"
+			fi
+			export PREVIOUS_DATADIR
+		fi
+	else
+		if [[ ${EBUILD_PHASE} == "config" ]]; then
+			local new_MY_DATADIR
+			new_MY_DATADIR=`"my_print_defaults" mysqld 2>/dev/null \
+				| sed -ne '/datadir/s|^--datadir=||p' \
+				| tail -n1`
+
+			if [[ ( -n "${new_MY_DATADIR}" ) && ( "${new_MY_DATADIR}" != "${MY_DATADIR}" ) ]]; then
+				ewarn "MySQL MY_DATADIR has changed"
+				ewarn "from ${MY_DATADIR}"
+				ewarn "to ${new_MY_DATADIR}"
+			fi
+		fi
+	fi
+
+	if [ "${MY_SOURCEDIR:-unset}" == "unset" ]; then
+		MY_SOURCEDIR=${SERVER_URI##*/}
+		MY_SOURCEDIR=${MY_SOURCEDIR%.tar*}
+	fi
+
+	export MY_SHAREDSTATEDIR MY_SYSCONFDIR
+	export MY_LIBDIR MY_LOCALSTATEDIR MY_LOGDIR
+	export MY_INCLUDEDIR MY_DATADIR MY_SOURCEDIR
+}
diff --git a/metadata/md5-cache/dev-db/mariadb-5.5.32 b/metadata/md5-cache/dev-db/mariadb-5.5.32
new file mode 100644
index 0000000..1684c7d
--- /dev/null
+++ b/metadata/md5-cache/dev-db/mariadb-5.5.32
@@ -0,0 +1,15 @@
+DEFINED_PHASES=compile config configure install postinst postrm preinst prepare setup test unpack
+DEPEND=|| ( >=sys-devel/gcc-3.4.6 >=sys-devel/gcc-apple-4.0 ) sys-devel/gnuconfig sys-devel/make >=dev-util/cmake-2.8.9 userland_GNU? ( >=sys-apps/findutils-4.4.0 ) ssl? ( >=dev-libs/openssl-0.9.6d ) kernel_linux? ( sys-process/procps ) >=sys-apps/sed-4 >=sys-apps/texinfo-4.7-r1 >=sys-libs/readline-4.1 >=sys-libs/zlib-1.2.3 oqgraph? ( >=dev-libs/boost-1.40.0 ) sphinx? ( app-misc/sphinx ) !minimal? ( pam? ( virtual/pam ) ) perl? ( !dev-db/mytop ) !dev-db/mysql !dev-db/mariadb-galera !dev-db/percona-server jemalloc? ( dev-libs/jemalloc ) tcmalloc? ( dev-util/google-perftools ) systemtap? ( >=dev-util/systemtap-1.3 ) kernel_linux? ( dev-libs/libaio ) virtual/yacc static? ( sys-libs/ncurses[static-libs] ) >=dev-util/cmake-2.4.3 >=dev-util/cmake-2.6.3
+DESCRIPTION=An enhanced, drop-in replacement for MySQL
+EAPI=4
+HOMEPAGE=http://mariadb.org/
+IUSE=debug embedded minimal +perl selinux ssl static test latin1 extraengine cluster max-idx-128 +community profiling oqgraph sphinx pam jemalloc tcmalloc systemtap pbxt
+KEYWORDS=*
+LICENSE=GPL-2
+PDEPEND=perl? ( >=dev-perl/DBD-mysql-2.9004 ) =virtual/mysql-5.5
+RDEPEND=ssl? ( >=dev-libs/openssl-0.9.6d ) kernel_linux? ( sys-process/procps ) >=sys-apps/sed-4 >=sys-apps/texinfo-4.7-r1 >=sys-libs/readline-4.1 >=sys-libs/zlib-1.2.3 oqgraph? ( >=dev-libs/boost-1.40.0 ) sphinx? ( app-misc/sphinx ) !minimal? ( pam? ( virtual/pam ) ) perl? ( !dev-db/mytop ) !dev-db/mysql !dev-db/mariadb-galera !dev-db/percona-server jemalloc? ( dev-libs/jemalloc ) tcmalloc? ( dev-util/google-perftools ) systemtap? ( >=dev-util/systemtap-1.3 ) kernel_linux? ( dev-libs/libaio ) !minimal? ( !prefix? ( dev-db/mysql-init-scripts ) ) selinux? ( sec-policy/selinux-mysql ) perl? ( virtual/perl-Getopt-Long dev-perl/TermReadKey virtual/perl-Term-ANSIColor virtual/perl-Time-HiRes )
+REQUIRED_USE=tcmalloc? ( !jemalloc ) jemalloc? ( !tcmalloc ) minimal? ( !cluster !extraengine !embedded ) static? ( !ssl ) pbxt? ( !embedded )
+SLOT=0
+SRC_URI=http://ftp.osuosl.org/pub/mariadb/mariadb-5.5.32/kvm-tarbake-jaunty-x86/mariadb-5.5.32.tar.gz http://ftp.rediris.es/mirror/MariaDB/mariadb-5.5.32/kvm-tarbake-jaunty-x86/mariadb-5.5.32.tar.gz http://maria.llarian.net/download/mariadb-5.5.32/kvm-tarbake-jaunty-x86/mariadb-5.5.32.tar.gz http://launchpad.net/maria/5.5/ongoing/+download/mariadb-5.5.32.tar.gz http://mirrors.fe.up.pt/pub/mariadb/mariadb-5.5.32/kvm-tarbake-jaunty-x86/mariadb-5.5.32.tar.gz http://ftp-stud.hs-esslingen.de/pub/Mirrors/mariadb/mariadb-5.5.32/kvm-tarbake-jaunty-x86/mariadb-5.5.32.tar.gz mirror://gentoo/mysql-extras-20130120-0100Z.tar.bz2 http://g3nt8.org/patches/mysql-extras-20130120-0100Z.tar.bz2 http://dev.gentoo.org/~robbat2/distfiles/mysql-extras-20130120-0100Z.tar.bz2 http://dev.gentoo.org/~jmbsvicetto/distfiles/mysql-extras-20130120-0100Z.tar.bz2
+_eclasses_=cmake-utils	92319f03251f1235bc887cc84e5aef21	eutils	a108f00cccac414097bcbbbb5de01762	flag-o-matic	c3131dc67d3bd39f044e92b8280505e4	gnuconfig	9200bfc8e0184357abfb86a08edd4fc3	multilib	fac675dcccf94392371a6abee62d909f	mysql-cmake	6329316a4e59ec427757411545e7c913	mysql-v2	0eab2e84614d992d6979a52aa5eab819	mysql_fx	f783e104c8bbd017eefc5359f327975b	prefix	21058c21ca48453d771df15500873ede	toolchain-funcs	48b38a216afb92db6314d6c3187abea3	user	9e552f935106ff0bc92af16da64b4b29	versionator	865bc8b2fc9fcfb6d520bdf5a110f5ed
+_md5_=ccf8f2348c20e2a540ca358b5ae428b8
diff --git a/metadata/md5-cache/dev-db/mysql-init-scripts-2.0_pre1-r6 b/metadata/md5-cache/dev-db/mysql-init-scripts-2.0_pre1-r6
new file mode 100644
index 0000000..51eb61c
--- /dev/null
+++ b/metadata/md5-cache/dev-db/mysql-init-scripts-2.0_pre1-r6
@@ -0,0 +1,10 @@
+DEFINED_PHASES=install postinst
+DEPEND=virtual/pkgconfig
+DESCRIPTION=Gentoo MySQL init scripts.
+HOMEPAGE=http://www.gentoo.org/
+KEYWORDS=*
+LICENSE=GPL-2
+RDEPEND=!<dev-db/mysql-5.1
+SLOT=0
+_eclasses_=eutils	a108f00cccac414097bcbbbb5de01762	multilib	fac675dcccf94392371a6abee62d909f	systemd	9f063b2cc19c5e8030911372aa246c4e	toolchain-funcs	48b38a216afb92db6314d6c3187abea3
+_md5_=f673901db080f43ac455345418693c9a
diff --git a/metadata/md5-cache/virtual/mysql-5.5 b/metadata/md5-cache/virtual/mysql-5.5
new file mode 100644
index 0000000..c0054ec
--- /dev/null
+++ b/metadata/md5-cache/virtual/mysql-5.5
@@ -0,0 +1,8 @@
+DEFINED_PHASES=-
+DESCRIPTION=Virtual for MySQL client or database
+EAPI=2
+IUSE=embedded minimal static
+KEYWORDS=*
+RDEPEND=|| ( =dev-db/mysql-5.5*[embedded=,minimal=,static=] =dev-db/mariadb-5.5*[embedded=,minimal=,static=] )
+SLOT=0
+_md5_=fd0cd7435ca0201130861c02815fcfb1
diff --git a/virtual/mysql/metadata.xml b/virtual/mysql/metadata.xml
new file mode 100644
index 0000000..0ea2af6
--- /dev/null
+++ b/virtual/mysql/metadata.xml
@@ -0,0 +1,8 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!DOCTYPE pkgmetadata SYSTEM "http://www.gentoo.org/dtd/metadata.dtd">
+<pkgmetadata>
+  <herd>mysql</herd>
+  <use>
+    <flag name='embedded'>Build embedded server (libmysqld)</flag>
+  </use>
+</pkgmetadata>
diff --git a/virtual/mysql/mysql-5.5.ebuild b/virtual/mysql/mysql-5.5.ebuild
new file mode 100644
index 0000000..2794594
--- /dev/null
+++ b/virtual/mysql/mysql-5.5.ebuild
@@ -0,0 +1,21 @@
+# Copyright 1999-2012 Gentoo Foundation
+# Distributed under the terms of the GNU General Public License v2
+# $Header: /var/cvsroot/gentoo-x86/virtual/mysql/mysql-5.5.ebuild,v 1.6 2012/12/05 11:24:27 grobian Exp $
+
+EAPI="2"
+
+DESCRIPTION="Virtual for MySQL client or database"
+HOMEPAGE=""
+SRC_URI=""
+
+LICENSE=""
+SLOT="0"
+KEYWORDS="*"
+IUSE="embedded minimal static"
+
+DEPEND=""
+# TODO: add Drizzle and MariaDB here
+RDEPEND="|| (
+	=dev-db/mysql-${PV}*[embedded=,minimal=,static=]
+	=dev-db/mariadb-${PV}*[embedded=,minimal=,static=]
+)"