Bug #74440 mysql_install_db not handling mysqld startup failure
Submitted: 19 Oct 2014 11:59 Modified: 9 Jan 2017 11:47
Reporter: Vlad Lesin Email Updates:
Status: Won't fix Impact on me:
Category:MySQL Server: Installing Severity:S3 (Non-critical)
Version:5.1, 5.5, 5.6, 5.6.22 OS:Any
Assigned to: CPU Architecture:Any

[19 Oct 2014 11:59] Vlad Lesin
Consider lp:mysql-server/5.6 revision 6130.

If we look into scripts/mysql_install_db.pl.in lines 753-958 are responsible for invoking mysqld in bootstrap mode and feeding the following files to it:
my $create_system_tables = "$pkgdatadir/mysql_system_tables.sql";
my $fill_system_tables = "$pkgdatadir/mysql_system_tables_data.sql";

The code use 'open(PIPE, "| $mysqld_install_cmd_line")' perl construction which allows easily work with pipes, but the return code of mysqld is not checked, so if something went wrong (for example mutually exclusive mysqld options present in config file) mysql_install_db will ignore the error and continue the execution.

I would propose to check the return value of perl "close" function when the pipe is closed. Here is the description how to check error code of the child on another side of pipe with "close":

"If the filehandle came from a piped open, close returns false if one of the other syscalls involved fails or if its program exits with non-zero status. If the only problem was that the program exited non-zero, $! will be set to 0 . Closing a pipe also waits for the process executing on the pipe to exit--in case you wish to look at the output of the pipe afterwards--and implicitly puts the exit status value of that command into $? and ${^CHILD_ERROR_NATIVE}." (http://perldoc.perl.org/functions/close.html)

In the case of unexpected mysqld termination mysql_install_db should be aborted with corresponding error message.

See also: https://bugs.launchpad.net/percona-server/+bug/1382782

How to repeat:
Run mysql_install_db in 5.6 with --enforce-gtid-consistency=1 --autocommit=0 options. The server terminates with the following error message:

ERROR: 1787 When @@GLOBAL.ENFORCE_GTID_CONSISTENCY = 1, the statements CREATE TEMPORARY TABLE and DROP TEMPORARY TABLE can be executed in a non-transactional context only, and require that AUTOCOMMIT = 1.

But mysql_install_db continues execution. As a result system tables will not be created and filled in but mysql_install_db reports about successful execution.

Suggested fix:
See https://bugs.launchpad.net/percona-server/+bug/1382782 related branches.
[20 Oct 2014 8:38] MySQL Verification Team
Hello Vlad Lesin,

Thank you for the report.
Verified as described.

[9 Jan 2017 11:47] Georgi Kodinov
Posted by developer:
The mysql_install_db is deprecated in 5.7 in favor of mysqld --initialize and it does not suffer the same issue.