Bug #84172 The pid-file value is ignored in the /etc/my.cnf option file

Submitted: 13 Dec 2016 6:22 Modified: 24 Feb 2017 2:01
Reporter: monty solomon Email Updates:
Status: Closed Impact on me:
None 
Category:MySQL Server: Packaging Severity:S3 (Non-critical)
Version:5.7.16 OS:CentOS (6.7)
Assigned to: CPU Architecture:Any

[13 Dec 2016 6:22] monty solomon
Description:
The pid-file value in the /etc/my.cnf file is being ignored. It appears that the mysqld script ignores the pid-file entry in the [mysqld] section of the /etc/my.cnf file and provides its own default value.

Various sections of the documentation indicate that the pid-file entry in the [mysqld] section would be used.

6.1.4 Server Command Options
https://dev.mysql.com/doc/refman/5.7/en/server-options.html

5.3.2 mysqld_safe — MySQL Server Startup Script
https://dev.mysql.com/doc/refman/5.7/en/mysqld-safe.html

5.3.3 mysql.server — MySQL Server Startup Script
https://dev.mysql.com/doc/refman/5.7/en/mysql-server.html

The documentation for systemd states that it doesn't use the pid-file in the [mysqld] section but RHEL/CentOS 6 uses mysqld and not systemd.

https://dev.mysql.com/doc/refman/5.7/en/using-systemd.html
2.5.10 Managing MySQL Server with systemd

How to repeat:
* Add a pid-file entry to only the [mysqld] section in /etc/my.cnf. Use a file name other than /var/run/mysqld/mysqld.pid

[mysqld]
pid-file = /tmp/monty.pid

* Start mysqld

service mysqld start

* Observe that the pid file used is /var/run/mysqld/mysqld.pid even though a different name was specified.

# ps -ef | grep mysql

/bin/sh /usr/bin/mysqld_safe ... --pid-file=/var/run/mysqld/mysqld.pid ...
/usr/sbin/mysqld ... --pid-file=/var/run/mysqld/mysqld.pid ...

* Examine the mysqld script and observe that it looks for the pid-file entry in the [mysqld_safe] section but not in the [mysqld] section.

# grep pid /etc/init.d/mysqld
get_mysql_option mysqld_safe pid-file "/var/run/mysqld/mysqld.pid"

Suggested fix:
Fix the mysqld script to read the pid-file from the [mysqld] section.
[16 Dec 2016 12:04] MySQL Verification Team
Hi,

Thanks for your report.

The pid is set by the "starting" app so not by the mysqld itself so the pid-file parameter is not in the [mysqld] section but in [mysqld-safe] section as mysqld_safe is what's setting it. So this is behaving as expected really and is not a bug.

If you feel strongly that our documentation is not clear enough how this works and where it goes you can create a documentation bug but with regards to this one the pid-file is not moving from [mysqld] to [mysqld-safe]

Take care
Bogdan
[16 Dec 2016 22:03] monty solomon
The documentation states that the [mysqld] section is widely read but the /etc/init.d/mysqld startup script is limiting itself to just the [mysqld_safe] section when looking for the pid file.

The documentation for the startup script states that the startup script reads the [mysqld] option file group but not the [mysqld_safe] group.

Here are the relevant excerpts.

Server Command Options
https://dev.mysql.com/doc/refman/5.7/en/server-options.html

mysqld reads options from the [mysqld] and [server] groups. mysqld_safe reads options from the [mysqld], [server], [mysqld_safe], and [safe_mysqld] groups. mysql.server reads options from the [mysqld] and [mysql.server] groups.

MySQL Server Startup Script
https://dev.mysql.com/doc/refman/5.7/en/mysql-server.html

Because mysql.server reads the [mysqld] option file group but not the [mysqld_safe] group
[16 Dec 2016 22:10] monty solomon
The documentation states in both of those sections that the startup script does not read from the [mysqld_safe] section but we can see that it is explicitly doing so.

# grep mysqld_safe /etc/init.d/mysqld 

get_mysql_option mysqld_safe log-error "/var/log/mysqld.log"
get_mysql_option mysqld_safe pid-file "/var/run/mysqld/mysqld.pid"
[18 Dec 2016 20:19] MySQL Verification Team
Hi,

Yes, as I said, it's documentation fault not server fault.

This parameter should be in the [mysqld-safe] section and not inside [mysqld] section, and yes it will not be used with systemd nor by any other starting system other then mysqld_safe (hence it's in mysqld-safe section).

I changed the bug category and verified it. When documentation team get to it they'll probably remove the problematic part of the text from our documentation

take care
Bogdan
[21 Dec 2016 11:47] monty solomon
I figured out why the pid file in the [mysqld] section used to work.

Oracle provides two different distributions of MySQL 5.6 for RHEL 6 and they use two different startup scripts (with different names). The mysql startup script in MySQL-server honors the pid file specified in the [mysqld] section of the /etc/my.cnf file. The mysqld startup script in the mysql-community-server does not honor the pid file specified in the [mysqld] section of the /etc/my.cnf file.

MySQL-server-5.6.35-1.el6.x86_64.rpm is available from the download section of the MySQL web site.

mysql-community-server-5.6.35-2.el6.x86_64.rpm is available in the yum repository.

# tar xvpf MySQL-5.6.35-1.el6.x86_64.rpm-bundle.tar

# rpm -ivf MySQL-*5.6.35*rpm --force

# rpm -qa | grep ^MySQL
MySQL-client-5.6.35-1.el6.x86_64
MySQL-shared-5.6.35-1.el6.x86_64
MySQL-devel-5.6.35-1.el6.x86_64
MySQL-test-5.6.35-1.el6.x86_64
MySQL-shared-compat-5.6.35-1.el6.x86_64
MySQL-server-5.6.35-1.el6.x86_64
MySQL-embedded-5.6.35-1.el6.x86_64

mysql  Ver 14.14 Distrib 5.6.35, for Linux (x86_64) using  EditLine wrapper
Server version:		5.6.35-log MySQL Community Server (GPL)

mysql> select @@pid_file;
+--------------------------------+
| @@pid_file                     |
+--------------------------------+
| /opt/mysql/dbprod/monty-q0.pid |
+--------------------------------+
1 row in set (0.00 sec)

root     15558     1  0 11:33 pts/1    00:00:00 /bin/sh /usr/bin/mysqld_safe --datadir=/opt/mysql/dbdata1/monty-q0 --pid-file=/opt/mysql/dbprod/monty-q0.pid

mysql    17206 15558  0 11:33 pts/1    00:00:00 /usr/sbin/mysqld --basedir=/usr --datadir=/opt/mysql/dbdata1/monty-q0 --plugin-dir=/usr/lib64/mysql/plugin --user=mysql --log-error=/opt/mysql/dblogs1/monty-q0/gen/error.log --open-files-limit=65535 --pid-file=/opt/mysql/dbprod/monty-q0.pid --socket=/opt/mysql/dbprod/monty-q0.sock --port=3306

# yum install mysql-community-*5.6.35*

# rpm -qa | grep ^mysql-community
mysql-community-devel-5.6.35-2.el6.x86_64
mysql-community-libs-compat-5.6.35-2.el6.x86_64
mysql-community-libs-5.6.35-2.el6.x86_64
mysql-community-client-5.6.35-2.el6.x86_64
mysql-community-embedded-5.6.35-2.el6.x86_64
mysql-community-test-5.6.35-2.el6.x86_64
mysql-community-bench-5.6.35-2.el6.x86_64
mysql-community-common-5.6.35-2.el6.x86_64
mysql-community-server-5.6.35-2.el6.x86_64
mysql-community-embedded-devel-5.6.35-2.el6.x86_64

mysql  Ver 14.14 Distrib 5.6.35, for Linux (x86_64) using  EditLine wrapper
Server version:		5.6.35-log MySQL Community Server (GPL)

mysql> select @@pid_file;
+----------------------------+
| @@pid_file                 |
+----------------------------+
| /var/run/mysqld/mysqld.pid |
+----------------------------+
1 row in set (0.00 sec)

root     20529     1  0 11:41 pts/1    00:00:00 /bin/sh /usr/bin/mysqld_safe --datadir=/opt/mysql/dbdata1/monty-q0 --socket=/opt/mysql/dbprod/monty-q0.sock --pid-file=/var/run/mysqld/mysqld.pid --basedir=/usr --user=mysql

mysql    22221 20529  0 11:41 pts/1    00:00:01 /usr/sbin/mysqld --basedir=/usr --datadir=/opt/mysql/dbdata1/monty-q0 --plugin-dir=/usr/lib64/mysql/plugin --user=mysql --log-error=/opt/mysql/dblogs1/monty-q0/gen/error.log --open-files-limit=65535 --pid-file=/var/run/mysqld/mysqld.pid --socket=/opt/mysql/dbprod/monty-q0.sock --port=3306
[24 Feb 2017 2:01] Paul DuBois
Posted by developer:
 
Noted in 5.5.55, 5.6.36, 5.7.18, 8.0.1 changelogs.

For System V init scripts for RPMs, the [mysqld] option-file section
was being ignored for some options, such as pid-file.

Portions of this website are copyright © 2001, 2002 The PHP Group

Page generated in 0.042 sec. using MySQL 8.4.7-u6-cloud

Timestamp references displayed by the system are UTC.
Content reproduced on this site is the property of the respective copyright holders.
It is not reviewed in advance by Oracle and does not necessarily represent the opinion of Oracle or any other party.