Bug #71462 mysqld_safe does not cooperate with log rotation when logging to a file
Submitted: 23 Jan 2014 22:58 Modified: 27 Jan 2014 18:58
Reporter: Andrew Gaul (OCA) Email Updates:
Status: Verified Impact on me:
None 
Category:MySQL Server: Logging Severity:S3 (Non-critical)
Version:5.7.3, 5.6.17, 5.5.35 OS:Linux
Assigned to: CPU Architecture:Any

[23 Jan 2014 22:58] Andrew Gaul
Description:
mysqld_safe does not cooperate with log rotation when logging to a file because it redirects stdout and stderr to a file at mysqld launch.  When this file rotates, mysqld will log to the renamed file instead of the new file.  Instead, it should log to a pipe which opens the correct file name for every message.

How to repeat:
mysqld_safe --skip-syslog --log-error=/var/log/mysql/mysql.log
rm -f /var/log/mysql/mysql.log
kill -s ABRT `pidof mysqld`
cat /var/log/mysql/mysql.log
[23 Jan 2014 23:29] Andrew Gaul
Suggested fix:
https://code.launchpad.net/~gaul/mysql-server/mysqld-safe-file
[24 Jan 2014 19:40] Sveta Smirnova
Thank you for the report.

I cannot repeat described behavior:

[sveta@delly mysql-trunk]$ ./bin/mysqld_safe --no-defaults --basedir=. --datadir=./data --skip-syslog --log-error=/tmp/bug71462.log &
[1] 14363
[sveta@delly mysql-trunk]$ 140124 21:36:42 mysqld_safe Logging to '/tmp/bug71462.log'.
140124 21:36:42 mysqld_safe Starting mysqld daemon with databases from ./data

[sveta@delly mysql-trunk]$ 
[sveta@delly mysql-trunk]$ cat /tmp/bug71462.log 
140124 21:36:42 mysqld_safe Starting mysqld daemon with databases from ./data
2014-01-24T19:36:43.806513Z 0 [Warning] TIMESTAMP with implicit DEFAULT value is deprecated. Please use --explicit_defaults_for_timestamp server option (see documentation for more details).
....
Version: '5.7.4-m14-debug'  socket: '/tmp/mysql.sock'  port: 3306  Source distribution
[sveta@delly mysql-trunk]$ rm -f /tmp/bug71462.log 
[sveta@delly mysql-trunk]$ cat /tmp/bug71462.log 
cat: /tmp/bug71462.log: No such file or directory
[sveta@delly mysql-trunk]$ kill -s ABRT `pidof mysqld`
[sveta@delly mysql-trunk]$ chown: changing ownership of `/tmp/bug71462.log': Operation not permitted
140124 21:36:55 mysqld_safe Number of processes running now: 0
140124 21:36:55 mysqld_safe mysqld restarted

[sveta@delly mysql-trunk]$ cat /tmp/bug71462.log 
140124 21:36:55 mysqld_safe Number of processes running now: 0
140124 21:36:55 mysqld_safe mysqld restarted
2014-01-24T19:36:55.949951Z 0 [Warning] TIMESTAMP with implicit DEFAULT value is deprecated. Please use --explicit_defaults_for_timestamp server option (see documentation for more details).
....

Please provide log of commands you used as I did and specify exact Linux and shell versions you use.
[24 Jan 2014 23:26] Andrew Gaul
I incompletely described the symptoms of this issue.  While the log file exists, it does not contain the backtrace from the SIGABRT handler.
[26 Jan 2014 12:04] Sveta Smirnova
Thank you for the feedback.

Verified as described.

In order for us to accept your contribution you need to sign Oracle Contributor Agreement as described in the "Contributions" tab of this bug report.
[27 Jan 2014 18:58] Andrew Gaul
I submitted the OCA as instructed.  Note that log rotation will cause mysqld to log to an unlinked file, losing these log messages and consuming an unbounded amount of storage.
[27 Jan 2014 19:59] Sveta Smirnova
Thank you, Andrew! Our engineering team will consider if and when they can include your patch.
[28 Feb 2014 11:17] Sveta Smirnova
Andrew,

I am sorry I missed one detail. Now, after you signed OCA, you should have a link in the "Contributions" tab which allows you to send the patch and register it as a contribution. Please do it: otherwise the contribution won't show on the devs list and can be missed. Thanks in advance!
[28 Feb 2014 18:03] Andrew Gaul
Open and close the log file to output to the correct file during log rotation.

(*) I confirm the code being submitted is offered under the terms of the OCA, and that I am authorized to contribute it.

Contribution: mysql_safe.patch (text/x-patch), 722 bytes.

[7 Apr 2014 11:41] Ståle Deraas
Andrew,

Will will incorporate your contribution in a coming release. Thank you for your contribution.
[28 Apr 2014 18:50] Diwaker Gupta
Hello, is there an updated/ETA on this bug, especially since a patch has been provided?
[24 Mar 2016 10:40] Mikael Davranche
Any news on this case?

Using mysqld_safe is the recommended way to launch MySQL. Using flush-logs is the recommended way to rotate logs. And both are not compatible...

We have this patch in production. It works! Should be nice to approve and merge this.