Bug #84263 mysql.server (MySQL Server Startup Script) can not work,and export some error.
Submitted: 19 Dec 2016 10:53 Modified: 24 Feb 2017 17:48
Reporter: song boomballa Email Updates:
Status: Closed Impact on me:
None 
Category:MySQL Server: Installing Severity:S2 (Serious)
Version:5.7.17 OS:CentOS (6.6)
Assigned to: Terje Røsten CPU Architecture:Any
Tags: mysql install,error of mysql.server (MySQL Server Startup Script)

[19 Dec 2016 10:53] song boomballa
Description:

In my correct initialization of MySQL, the need to create a mysql.server automatically start the script,I  put /support-files/mysql.server /etc/init.d/mysql copy, and filled on the absolute directory basedir and datadir catalog. Then start on the error. The errors are as follows:

[root@localhost mysql]# /etc/init.d/mysql start
Starting MySQL.Logging to '/opt/app/mysql/data/localhost.localdomain.err'.
2016-12-19T18:29:20.971210Z mysqld_safe The file /usr/local/mysql/bin/mysqld
does not exist or is not executable. Please cd to the mysql installation
directory and restart this script from there as follows:
./bin/mysqld_safe&
See http://dev.mysql.com/doc/mysql/en/mysqld-safe.html for more information
 ERROR! The server quit without updating PID file (/opt/app/mysql/tmp/localhost.pid).

I suspect that if not in accordance with the official manual designated basedir /usr/local/mysql, there will be this mistake, I feel very inconvenient.

How to repeat:

Ready to work:

Unzip the mysql binary package into the specified directory

shell> tar -zxvf mysql-5.7.17-linux-glibc2.5-x86_64.tar.gz -C /opt/app/ && mv /opt/app/mysql-5.7.17-linux-glibc2.5-x86_64 mysql

My basedir=/opt/app/mysql, my.cnf also inside.

[mysqld]
# Basic
port            = 24081
user            = mysql
basedir         = /opt/app/mysql
datadir         = /opt/app/mysql/data
tmpdir          = /opt/app/mysql/tmp
socket          = /opt/app/mysql/tmp/mysql.sock
pid-file        = /opt/app/mysql/tmp/localhost.pid

1. Add the mysql user, create the required directory and empower.

shell> useradd mysql -s /sbin/nologin
shell> mkdir {data,logs,tmp}&&chown -R mysql.mysql {data,logs,tmp}

2. To initialize

shell> ./bin/mysqld --defaults-file=/opt/app/mysql/my.cnf --user=mysql --initialize
 
However, the initialization result is normal

3. Then copy the mysql.server to /etc/init.d/ and modify the directory basedir and datadir.

shell> cp support-files/mysql.server /etc/init.d/mysql
shell> vim /etc/init.d/mysql

Add the following two items:

basedir=/opt/app/mysql
datadir=/opt/app/mysql/data

4. Try to start mysql

[root@localhost mysql]# /etc/init.d/mysql start
Starting MySQL.Logging to '/opt/app/mysql/data/localhost.localdomain.err'.
2016-12-19T18:45:32.846347Z mysqld_safe The file /usr/local/mysql/bin/mysqld
does not exist or is not executable. Please cd to the mysql installation
directory and restart this script from there as follows:
./bin/mysqld_safe&
See http://dev.mysql.com/doc/mysql/en/mysqld-safe.html for more information
 ERROR! The server quit without updating PID file (/opt/app/mysql/tmp/localhost.pid).

Suggested fix:
I suspect that if not in accordance with the official manual designated basedir /usr/local/mysql, there will be this mistake, I feel very inconvenient.

But,as an absolute supporter of mysql speaking, this will affect the user experience, basedir and datadir sometimes need to be specified in accordance with their respective circumstances. Feel percona official at this point to do better.

I hope mysql official can improve the user experience, become better. I will always support mysql.
[19 Dec 2016 11:03] song boomballa
2. To initialize

shell> ./bin/mysqld --defaults-file=/opt/app/mysql/my.cnf --user=mysql --initialize --basedir=/opt/app/mysql --datadir=/opt/app/mysql/data

this is the initialize statement.
[19 Dec 2016 12:29] MySQL Verification Team
Thank you for the report.
Does adding [mysql.server] group to the global conf file(/etc/my.cnf) helps?

[mysql.server]
basedir=/opt/app/mysql

Thanks,
Umesh
[19 Dec 2016 18:53] Terje Røsten
Hi!

Thanks for your report!

It seems mysqld_safe is started with an absolute path in this case ($bindir becomes /opt/app/mysql/bin), 
then will mysqld_safe prefer the compiled in absolute path due to:

case "$0" in
  /*)
  MY_PWD='/usr/local/mysql'

which don't match your basedir of /opt/app/mysql, and it ends up in mismatch.

Can you do the following change:

--- support-files/mysql.server  2016-11-28 16:39:45.000000000 +0100
+++ /etc/init.d/mysql   2016-12-19 19:48:21.341556317 +0100
@@ -275,7 +275,7 @@
     then
       # Give extra arguments to mysqld with the my.cnf file. This script
       # may be overwritten at next upgrade.
-      $bindir/mysqld_safe --datadir="$datadir" --pid-file="$mysqld_pid_file_path" $other_args >/dev/null &
+      bin/mysqld_safe --datadir="$datadir" --pid-file="$mysqld_pid_file_path" $other_args >/dev/null &
       wait_for_pid created "$!" "$mysqld_pid_file_path"; return_value=$?
 
       # Make lock for RedHat / SuSE

That is changing path to mysqld_safe to a relative path.

Can you please try and see if this change helps?
[20 Dec 2016 2:28] song boomballa
HI,Umesh:

Thank you for your reply.
  

My configuration file my.cnf is placed in / opt / app / mysql directory, I try to add
[Mysql.server]
Basedir = / opt / app / mysql

But the problem already exists, the error message without any change.

[root@localhost ~]# vim /opt/app/mysql/my.cnf 
[root@localhost ~]# /etc/init.d/mysql start
Starting MySQL.Logging to '/opt/app/mysql/data/localhost.localdomain.err'.
2016-12-20T10:23:03.923878Z mysqld_safe The file /usr/local/mysql/bin/mysqld
does not exist or is not executable. Please cd to the mysql installation
directory and restart this script from there as follows:
./bin/mysqld_safe&
See http://dev.mysql.com/doc/mysql/en/mysqld-safe.html for more information
 ERROR! The server quit without updating PID file (/opt/app/mysql/tmp/localhost.pid).

Above for the error export message.
[20 Dec 2016 3:04] song boomballa
Hi,Terje Røsten:

Thank you for your reply.

According to your prompt, mysql.server can be used normally.

But this is very inconvenient, if basedir not installed in /usr/local/mysql, you need to manually modify the mysql.server, this is not a very interesting thing, this issue can be modified in the future version of it? Because a lot of users will not necessarily based on /usr/local/mysql basedir.

I really hope that the future version of mysql can be improved for this issue.
[25 Dec 2016 4:12] MySQL Verification Team
also; http://bugs.mysql.com/bug.php?id=84173
[25 Dec 2016 10:26] Terje Røsten
> This issue can be modified in the future version of it?

We hope to include a fix in the next release.
[24 Feb 2017 17:48] Paul DuBois
Posted by developer:
 
Noted in 5.5.55, 5.6.36, 5.7.18, 8.0.1 changelogs.

A recent change to mysqld_safe caused the mysql.server script to be
unable to start it if the base directory was specified as an absolute
path that differed from the compiled-in default absolute path.
[12 Apr 2017 13:19] MySQL Verification Team
Bug #85901 marked as duplicate of this one