Bug #73845 mysql_install_db now requires --datadir and --lc-messages-dir options?
Submitted: 9 Sep 2014 3:15 Modified: 15 Sep 2014 11:55
Reporter: Shane Bester (Platinum Quality Contributor) Email Updates:
Status: Not a Bug Impact on me:
None 
Category:MySQL Server: Installing Severity:S3 (Non-critical)
Version:5.7.6 OS:Any
Assigned to: CPU Architecture:Any

[9 Sep 2014 3:15] Shane Bester
Description:
for years the ./scripts/mysql_install_db from a .tar.gz package used ./data and ./share as the default option.  Now, it doesn't work since it was rewritten:

[sbester@fc17 mysql-5.7.6-m16-linux-x86_64]$ ./bin/mysql_install_db
[ERROR]   The data directory needs to be specified.

---> ok, so we specify datadir but it fails with obscure message:

[sbester@fc17 mysql-5.7.6-m16-linux-x86_64]$ ./bin/mysql_install_db --datadir=./data
[ERROR]   The child process terminated prematurely. Errno= 32
[ERROR]   Failed to execute /home/sbester/mysql/release/mysql-5.7.6-m16-linux-x86_64/bin/mysqld --no-defaults --bootstrap --datadir=./data --lc-messages-dir=/usr/share/mysql --lc-messages=en_US
-- server log begin --

-- server log end --

---> We provide both options, yet there is already data now:

[sbester@fc17 mysql-5.7.6-m16-linux-x86_64]$ ./bin/mysql_install_db --datadir=./data --lc-messages-dir=./share
ERROR]   The data directory './data' already exist and is not empty.

---> Success after cleaning up:

[sbester@fc17 mysql-5.7.6-m16-linux-x86_64]$ rm -rf data
[sbester@fc17 mysql-5.7.6-m16-linux-x86_64]$ ./bin/mysql_install_db --datadir=./data --lc-messages-dir=./share

How to repeat:
Build a standalone .tar.gz package.

tar zxvf mysql-5.7.6-m16-linux-x86_64.tar.gz
cd mysql-5.7.6-m16-linux-x86_64
./bin/mysql_install_db --no-defaults

Suggested fix:
why would /usr/share/mysql be used at all?   I didn't specify it and it isn't listed in the output of ./bin/mysql_install_db --help as a default for --lc-messages-dir.   Also, a .tar.gz is meant to be usable anywhere, not installed in some common location by default.
[9 Sep 2014 6:59] MySQL Verification Team
Hello Shane,

Thank you for report.
Verified as described.

// Tried with latest build from pb

13146215.mysql-advanced-5.7.6-m16-linux-x86_64.tar.gz

[ushastry@cluster-repo server]$ tar -zxvf 13146215.mysql-advanced-5.7.6-m16-linux-x86_64.tar.gz

[ushastry@cluster-repo server]$ mv mysql-advanced-5.7.6-m16-linux-x86_64 mysql-advanced-5.7.6
[ushastry@cluster-repo server]$ cd mysql-advanced-5.7.6
[ushastry@cluster-repo mysql-advanced-5.7.6]$ ls -l
total 132
drwxrwxr-x  2 ushastry ushastry  4096 Sep 11 00:46 bin
drwxrwxr-x  2 ushastry ushastry  4096 Sep 11 00:46 docs
drwxrwxr-x  3 ushastry ushastry  4096 Sep 11 00:46 include
-rw-r--r--  1 ushastry ushastry 89308 Sep  5 20:21 INSTALL-BINARY
drwxrwxr-x  3 ushastry ushastry  4096 Sep 11 00:46 lib
-rw-r--r--  1 ushastry ushastry  2729 Sep  5 20:22 LICENSE.mysql
drwxrwxr-x  4 ushastry ushastry  4096 Sep 11 00:46 man
drwxrwxr-x 10 ushastry ushastry  4096 Sep 11 00:46 mysql-test
-rw-r--r--  1 ushastry ushastry  1449 Sep  5 20:22 README
drwxrwxr-x 28 ushastry ushastry  4096 Sep 11 00:46 share
drwxrwxr-x  4 ushastry ushastry  4096 Sep 11 00:46 sql-bench
drwxrwxr-x  2 ushastry ushastry  4096 Sep 11 00:46 support-files

//  without any options
[root@cluster-repo mysql-advanced-5.7.6]# bin/mysql_install_db
2014-09-11 01:21:38 [ERROR]   The data directory needs to be specified.
[root@cluster-repo mysql-advanced-5.7.6]#

// with datadir

[root@cluster-repo mysql-advanced-5.7.6]# bin/mysql_install_db --datadir=./data/
2014-09-11 01:22:00 [ERROR]   The child process terminated prematurely. Errno= 32
2014-09-11 01:22:00 [ERROR]   Failed to execute /data/ushastry/server/mysql-advanced-5.7.6/bin/mysqld --no-defaults --bootstrap --datadir=./data --lc-messages-dir=/usr/share/mysql --lc-messages=en_US
-- server log begin --

-- server log end --

// Complains about existing datadir
[root@cluster-repo mysql-advanced-5.7.6]# bin/mysql_install_db --datadir=./data/ --lc-messages-dir=./share/
2014-09-11 01:25:19 [ERROR]   The data directory './data/' already exist and is not empty.
[root@cluster-repo mysql-advanced-5.7.6]#
[root@cluster-repo mysql-advanced-5.7.6]# rm -rf data

// 
[root@cluster-repo mysql-advanced-5.7.6]# bin/mysql_install_db --datadir=./data/ --lc-messages-dir=./share/
[root@cluster-repo mysql-advanced-5.7.6]# ls -l data/
total 110632
-rw------- 1 root root     1680 Sep 11 01:25 ca-key.pem
-rw-r--r-- 1 root root      913 Sep 11 01:25 ca.pem
-rw-r--r-- 1 root root      913 Sep 11 01:25 client-cert.pem
-rw------- 1 root root     1676 Sep 11 01:25 client-key.pem
-rw-rw---- 1 root root 12582912 Sep 11 01:25 ibdata1
-rw-rw---- 1 root root 50331648 Sep 11 01:25 ib_logfile0
-rw-rw---- 1 root root 50331648 Sep 11 01:25 ib_logfile1
drwx------ 2 root root     4096 Sep 11 01:25 mysql
drwx------ 2 root root     4096 Sep 11 01:25 performance_schema
-rw------- 1 root root     1676 Sep 11 01:25 private_key.pem
-rw-r--r-- 1 root root      452 Sep 11 01:25 public_key.pem
-rw-r--r-- 1 root root      913 Sep 11 01:25 server-cert.pem
-rw------- 1 root root     1676 Sep 11 01:25 server-key.pem

Thanks,
Umesh
[9 Sep 2014 7:06] MySQL Verification Team
I believe this behavior is due to the WL - http://wl.no.oracle.com/worklog/Server-Sprint/?tid=7688

Even if this is expected as per F-14, this change require proper documentation to avoid any confusion, also noticed that this binary version of mysql_install_db is not verbose by default which means unless someone reads manual it is not possible to know where the mysql's root user password is written, explicitly need to pass --datadir which is inconvenient in *some cases.
[11 Sep 2014 16:44] Jess Balint
Specifying --basedir=`pwd` is also a possible fix. This used to be default, I guess datadir=$basedir/data was nice too.
[15 Sep 2014 11:55] Erlend Dahl
[15 Sep 2014 3:02] Kristofer Pettersson

m_i_db would typically search the defaults for a suitable path for the
lc_messages_dir (see assert_valid_language_dir()). However, the program
doesn't verify that there is a binary compatibility between the actual data
files and the identified language dir. Since the m_i_db seem to have found a
valid language dir my assumption is that there is an old install and that the
my.cnf file specifies the location to the old data files. Running m_i_db with
--no-defaults as the first parameter might be a better option.
In either case, understanding where the database components reside is a
reasonable requirement for anyone wanting to deploy the server on his own.
The reason that the previous m_i_db program worked, might as well have been
chance.

m_i_db will always require --datadir to be specified. This is an important
option as it points to where the databases will be stored. Awareness of this
localhost should be considered critical in most deployment scenarios.

m_i_db is aware of some common deployment topologies and tries to make some
guesses about the whereabouts of different components. Using the --verbose
option a user can identify which directories are being searched in case a
file is missing. If there are old files in the path or if different
topologies are mixed, then the wrong files might get picked by mistake.
Hence, if a custom deployment must be done without Oracle deployment scripts,
it's recommended that all the appropriate options are used. The m_i_db is
using many different search paths per default and one is
INSTALL_MYSQLSHAREDIR/english which is specified during compile time
depending on the intended target platform. We might need to check that this
INSTALL_MYSQLSHAREDIR is properly defined for the tar.gz package in this bug
report.

Since the requirement on most deployments is that there shouldn't be any
output, the default behaviour is to be silent. This is per design in response
to requirements.

Now, I can't see why a note which states that it isn't possible to create a
tmp dir followed by a error that the tmp dir can't be created won't trigger
an investigation of the effective privileges the process is executing under.
This should be standard procedure for anyone working in an *inx environment.

The final obscure failure to start mysqld is however unfortunate, and maybe
some additional hints to the reason of the failure can be added. A natural
first choice should however be to use the existing options listed in m_i_db.

As for refusing to run m_i_db on an existing datadir seems very natural as
you are not suppose to use m_i_db as an upgrade tool, because it isn't. We
have the mysql_upgrade tool for upgrades. All of this might be documentation
issues of course and something we need to emphasis.

The arguments: it used to work before, aren't really valid, because it really
didn't use to work. That's why we rewrote it with stricter requirements.

Please see how this new avatar of mysql_install_db can frustrate users:

Why are you doing this?
[ushastry@cluster-repo mysql-advanced-5.7.6]$ sudo rm -rf /tmp/576/
<-- removed datadir
[ushastry@cluster-repo mysql-advanced-5.7.6]$ sudo mkdir -p /tmp/576
<-- created datadir
[ushastry@cluster-repo mysql-advanced-5.7.6]$ sudo touch /tmp/576/1
<-- created single file

It should be possible to just specify the location of the datadir (given that
you have the actual effective privileges to create a dir). The above steps
are no way mandatory but a result of circumstances unique to some very
specific deployment.
[8 Jan 2015 15:20] Tony Darnell
I am having problems installing 5.7.5 from labs.

$ bin/mysql_install_db --basedir=`pwd` --datadir=../data --user=mysql --lc-messages-dir=./share -v
2015-01-08 10:18:03 [NOTE]    Using existing directory ../data
2015-01-08 10:18:03 [NOTE]    Generating random password to /home/mysql/.mysql_secret...done.
2015-01-08 10:18:03 [NOTE]    Executing /usr/local/mysql/bin/mysqld --no-defaults --bootstrap --datadir=../data --lc-messages-dir=./share --lc-messages=en_US --basedir=/usr/local/mysql
2015-01-08 10:18:03 [NOTE]    Creating system tables...failed.
2015-01-08 10:18:03 [ERROR]   The child process terminated prematurely. Errno= 32
2015-01-08 10:18:03 [ERROR]   Failed to execute /usr/local/mysql/bin/mysqld --no-defaults --bootstrap --datadir=../data --lc-messages-dir=./share --lc-messages=en_US --basedir=/usr/local/mysql
-- server log begin --

-- server log end --