Bug #87226 mysqld_safe will force-set DATADIR to /usr/data and
Submitted: 27 Jul 2017 17:10 Modified: 25 Sep 2017 13:06
Reporter: Brian Fujito Email Updates:
Status: No Feedback Impact on me:
None 
Category:MySQL Server: Installing Severity:S3 (Non-critical)
Version:5.6.37-1ubuntu14.04 OS:Ubuntu (trusty 14.04.5 LTS)
Assigned to: MySQL Verification Team CPU Architecture:Any

[27 Jul 2017 17:10] Brian Fujito
Description:
I am installing MySQL 5.6.37 on an Ubuntu 14.04.5 server.  I am using the apt configs to force usage of 5.6 instead of 5.7.  When mysql attempts to start up, it throws errors suggesting that it is looking in /usr/data for the data directories.  

It fails like this, when I call mysqld_safe the way that the package-provided init scripts run (note: I have changed my hostname to "myserver")

======
root@myserver:/etc/mysql# su - mysql -s /bin/bash -c "mysqld_safe > /dev/null &"
No directory, logging in with HOME=/
root@testbotnextgen-redpanda-i-061857e3:/etc/mysql# /usr/bin/mysqld_safe: 637: /usr/bin/mysqld_safe: cannot create /usr/data/myserver.err: Directory nonexistent
Logging to '/usr/data/testbotnextgen-redpanda-i-061857e3.vpcint.tioscapital.com.err'.
/usr/bin/mysqld_safe: 138: /usr/bin/mysqld_safe: cannot create /usr/data/myserver.err: Directory nonexistent
/usr/bin/mysqld_safe: 1: eval: cannot create /usr/data/MYSERVER.err: Directory nonexistent
/usr/bin/mysqld_safe: 886: /usr/bin/mysqld_safe: cannot create /usr/data/myserver.err: Directory nonexistent
/usr/bin/mysqld_safe: 138: /usr/bin/mysqld_safe: cannot create /usr/data/myserver.err: Directory nonexistent
======

Consistent with the way MySQL has normally worked, my databases data files are stored in /var/lib/mysql, not /usr/data.  I have config specs in /etc/mysql/my.cnf to ensure that /var/lib/mysql is the data directory.

I have other servers that I configured earlier using mysql 5.6.35-1ubuntu14.04.  That worked fine.

I did a diff of  /usr/bin/mysqld_safe in 5.6.35 (working) and 5.6.37 (broken)

The new 5.6.37 mysqld_safe has this block of code in it:

*****************************
# Try where the binary installs put it
if test -d $MY_BASEDIR_VERSION/data/mysql
then
  DATADIR=$MY_BASEDIR_VERSION/data
  if test -z "$defaults" -a -r "$DATADIR/my.cnf"
  then
    defaults="--defaults-extra-file=$DATADIR/my.cnf"
  fi
# Or just give up and use our compiled-in default
else
  DATADIR=/usr/data
fi
*****************************

At the end, it defaults to /usr/data.  In 5.6.35 it defaulted to /var/lib/mysql

The new 5.6.37 mysqld_safe adds some work in the parameter parsing of --datadir to remove a trailing /.  

How to repeat:
Install mysql-server 5.6.37 on Ubuntu 14.04

Have your my.cnf specify /var/lib/mysql as the data directory

Attempt to start mysql with:
  service start mysql

See errors.

Suggested fix:
The default DATADIR should be /var/lib/mysql in line 479 of mysqld_safe
[27 Jul 2017 19:50] Brian Fujito
I have also found that /usr/bin/mysql_install_db now set to default to /usr/data:

******
unless ( $opt->{ldata} )
{
  $opt->{ldata} = '/usr/data';
}
******

Since the /etc/init.d/mysql calls on mysql_install_db and mysqld_safe without passing a datadir option, we get stuck using defaults.

In the case of mysqld_safe, even if we were to change /etc/init.d/mysql to specify a datadir, it will get ignored and overwritten as shown in my original post.
[27 Jul 2017 19:57] Brian Fujito
Sorry -- to clarify my latest comment... On the latest MySQL 5.6.37, the call to mysql_install_db is actually in the new file:

/usr/share/mysql/mysql-helpers

I would argue that in there, in the "verify_database()" function, we should be calling

su - mysql -s /bin/bash -c "mysql_install_db --user=mysql --datadir=$MYSQLDATA > /dev/null"
[28 Jul 2017 17:43] Brian Fujito
The most straight-forward changes would be to set the defaults to /var/lib/mysql:

sed -i "s;/usr/data;/var/lib/mysql;g" /usr/bin/mysql_install_db
sed -i "s;DATADIR=/usr/data;DATADIR=/var/lib/mysql;" /usr/bin/mysqld_safe

Thanks,
Brian
[25 Aug 2017 13:06] MySQL Verification Team
Hi,
The workaround you mentioned (change defaults) will work. Now I have to ask, what binaries are you using? How did you install mysql 5.6 on that ubuntu14

all best
Bogdan
[26 Sep 2017 1:00] Bugs System
No feedback was provided for this bug for over a month, so it is
being suspended automatically. If you are able to provide the
information that was originally requested, please do so and change
the status of the bug back to "Open".