Bug #33881 log-bin and relay-log places files in an unsafe and wrong directory by default
Submitted: 16 Jan 2008 5:07 Modified: 23 Jan 2008 23:39
Reporter: Robin Johnson Email Updates:
Status: Duplicate Impact on me:
None 
Category:MySQL Server: Replication Severity:S2 (Serious)
Version:5.0.44, 5.0.54 OS:Any
Assigned to: CPU Architecture:Any

[16 Jan 2008 5:07] Robin Johnson
Description:
If you do not explicitly specify the directories for log-bin and relay-log, then it the MYSQL_LOG::generate_name function uses the pidfile name and directory to create the files.

The documentation however states:
http://dev.mysql.com/doc/refman/5.0/en/slave-logs.html
"By default, the slave server creates relay log files in its data directory."

This is specifically a problem when /var/run is used for the pidfile, as /var/run is subject to being erased on boot per the FHS:
http://www.pathname.com/fhs/pub/fhs-2.3.html#VARRUNRUNTIMEVARIABLEDATA
[snip]
This directory contains system information data describing the system since it
was booted. Files under this directory must be cleared (removed or truncated as
appropriate) at the beginning of the boot process. 
[/snip]

Downstream bug is http://bugs.gentoo.org/show_bug.cgi?id=205174

How to repeat:
To reproduce this, set the following in your my.cnf:
[mysqld]
datadir = /var/lib/mysql/
pid-file = /var/run/mysqld/mysqld.pid
log-bin

Then start mysqld, and check the contents of /var/run/mysqld/.

I have reproduced on 5.0.44 and 5.0.54 myself.

Suggested fix:
The MYSQL_LOG::generate_name behavior must be changed to use the basename of the pidfile, combined with the datadir, to match the documentation and not have the data deleted every reboot.
[23 Jan 2008 23:04] Sveta Smirnova
Please do not submit the same bug more than once. An existing bug report already describes this very problem. Even if you feel that your issue is somewhat different, the resolution is likely
to be the same. Because of this, we hope you add your comments to the original bug instead.

Thank you for your interest in MySQL.

Duplicate of bug #25192
[23 Jan 2008 23:15] Robin Johnson
That bug is not the same issue. It deals with incorrect parsing of the value used by relay-log and log-bin, while my bug deals with those options using the wrong directory (/var/run/mysqld/ instead of $datadir).

As I stated in my initial report, the MYSQL_LOG::generate_name() function incorrectly uses the full path of the pidfile, rather than $datadir/`basename $pid-file` to create the binary and relay logs.
[23 Jan 2008 23:39] Sveta Smirnova
Thank you for the feedback.

Sorry: set as duplicate of wrong report. Correct is bug #33693