Bug #75507 --log-bin wrongly processes basename with a dot ('.')
Submitted: 14 Jan 2015 17:47 Modified: 16 Jan 2015 10:31
Reporter: Valeriy Kravchuk Email Updates:
Status: Verified Impact on me:
None 
Category:MySQL Server: Replication Severity:S2 (Serious)
Version:5.6, any?, 5.6.22, 5.7.6, 5.7.20 OS:Any
Assigned to: CPU Architecture:Any
Tags: --log-bin, log_bin, relay_log

[14 Jan 2015 17:47] Valeriy Kravchuk
Description:
Manual (http://dev.mysql.com/doc/refman/5.6/en/replication-options-binary-log.html#option_mysqld_l...) says:

"The option value, if given, is the basename for the log sequence. The server creates binary log files in sequence by adding a numeric suffix to the basename. It is recommended that you specify a basename (see Section B.5.8, “Known Issues in MySQL”, for the reason). Otherwise, MySQL uses host_name-bin as the basename."

It says nothing about any restriction on basename. But if you use dot ('.') there, anything after the dot is truncated. Same probably applies to relay_log setting as well.

Linux basename utility that one may have in mind preserves "suffixes" by default:

[openxs@centos ~]$ basename a.b.c.a-bin-log
a.b.c.a-bin-log
[openxs@centos ~]$ basename /var/lib/mysql/a.b.c.a-bin-log
a.b.c.a-bin-log

How to repeat:
Set log-bin to a name with dot, like this:

[openxs@centos ~]$ cat /etc/my.cnf | grep log-bin
log-bin=a.b.c.a-bin-log

Now enjoy:

mysql> show variables like 'log_bin%';
+---------------------------------+------------------------+
| Variable_name                   | Value                  |
+---------------------------------+------------------------+
| log_bin                         | ON                     |
| log_bin_basename                | /var/lib/mysql/a       |
| log_bin_index                   | /var/lib/mysql/a.index |
| log_bin_trust_function_creators | OFF                    |
| log_bin_use_v1_row_events       | OFF                    |
+---------------------------------+------------------------+
5 rows in set (0.01 sec)

[root@centos openxs]# ls -l /var/lib/mysql/a*
-rw-rw----. 1 mysql mysql 224 Jan 14 19:34 /var/lib/mysql/a.000001
-rw-rw----. 1 mysql mysql  11 Jan 14 19:34 /var/lib/mysql/a.index
-rw-rw----. 1 mysql mysql  56 Jun  6  2014 /var/lib/mysql/auto.cnf

If you set relay_log to something like a.b.c.a-relay-log, you'll get a nice mix up of binary logs and relay logs on slave... Now think about naming logs after host name explicitly to imagine the impact.

Suggested fix:
Do not truncate basename for log_bin and relay_log at the first dot.

Alternatively, document how it is really processed to get log names.
[16 Jan 2015 10:31] Umesh Shastry
Hello Valeriy,

Thank you for the report and test case.
Observed similar behavior with 5.6.22.

Thanks,
Umesh
[16 Jan 2015 10:32] Umesh Shastry
/ 5.6.22

[root@cluster-repo ~]# vi /etc/my.cnf
[root@cluster-repo ~]# cat /etc/my.cnf | grep log_bin
log_bin=a.b.c.a-bin-log

[root@cluster-repo ~]# /etc/init.d/mysqld restart
Stopping mysqld:                                           [  OK  ]
Starting mysqld:                                           [  OK  ]
[root@cluster-repo ~]# ls -l /var/lib/mysql/
total 1393484
-rw-rw---- 1 mysql mysql        120 Jan 18 17:27 a.000001
-rw-rw---- 1 mysql mysql         11 Jan 18 17:27 a.index

[(none)]> show variables like 'log_bin%';
+---------------------------------+------------------------+
| Variable_name                   | Value                  |
+---------------------------------+------------------------+
| log_bin                         | ON                     |
| log_bin_basename                | /var/lib/mysql/a       |
| log_bin_index                   | /var/lib/mysql/a.index |
| log_bin_trust_function_creators | OFF                    |
| log_bin_use_v1_row_events       | OFF                    |
+---------------------------------+------------------------+
5 rows in set (0.00 sec)

[(none)]> show master logs;
+----------+-----------+
| Log_name | File_size |
+----------+-----------+
| a.000001 |       120 |
+----------+-----------+
1 row in set (0.00 sec)

[(none)]> flush logs;
Query OK, 0 rows affected (0.01 sec)

[(none)]> show master logs;
+----------+-----------+
| Log_name | File_size |
+----------+-----------+
| a.000001 |       159 |
| a.000002 |       120 |
+----------+-----------+
2 rows in set (0.00 sec)
[16 Jan 2015 10:35] Umesh Shastry
// 5.7.6

bin/mysql_install_db --basedir=/export/umesh/mysql-5.7.6 --datadir=/export/umesh/mysql-5.7.6/75510 -v

[umshastr@hod03]/export/umesh/mysql-5.7.6: bin/mysqld --basedir=/export/umesh/mysql-5.7.6 --datadir=/export/umesh/mysql-5.7.6/75510 --core-file --socket=/tmp/mysql_ushastry.sock  --port=15000 --log-error=/export/umesh/mysql-5.7.6/75510/log.err --log-bin=a.b.c.d.a-bin --server-id=1 2>&1 &

mysql> show variables like '%version%';
+-------------------------+---------------------------------------------------------+
| Variable_name           | Value                                                   |
+-------------------------+---------------------------------------------------------+
| innodb_version          | 5.7.6                                                   |
| protocol_version        | 10                                                      |
| slave_type_conversions  |                                                         |
| version                 | 5.7.6-m16-enterprise-commercial-advanced-log            |
| version_comment         | MySQL Enterprise Server - Advanced Edition (Commercial) |
| version_compile_machine | x86_64                                                  |
| version_compile_os      | Linux                                                   |
+-------------------------+---------------------------------------------------------+
7 rows in set (0.00 sec)

mysql> show variables like 'log_bin%';
+---------------------------------+-----------------------------------------+
| Variable_name                   | Value                                   |
+---------------------------------+-----------------------------------------+
| log_bin                         | ON                                      |
| log_bin_basename                | /export/umesh/mysql-5.7.6/75510/a       |
| log_bin_index                   | /export/umesh/mysql-5.7.6/75510/a.index |
| log_bin_trust_function_creators | OFF                                     |
| log_bin_use_v1_row_events       | OFF                                     |
+---------------------------------+-----------------------------------------+
5 rows in set (0.00 sec)

mysql> show master logs;
+----------+-----------+
| Log_name | File_size |
+----------+-----------+
| a.b.c.d  |       120 |
| a.b.c.d  |       120 |
+----------+-----------+
2 rows in set (0.00 sec)

mysql> flush logs;
Query OK, 0 rows affected (0.00 sec)

mysql> show master logs;
+----------+-----------+
| Log_name | File_size |
+----------+-----------+
| a.b.c.d  |       120 |
| a.b.c.d  |       120 |
| a.b.c.d  |       120 |
+----------+-----------+
3 rows in set (0.00 sec)

mysql> flush logs;
Query OK, 0 rows affected (0.00 sec)

mysql> show master logs;
+----------+-----------+
| Log_name | File_size |
+----------+-----------+
| a.b.c.d  |       120 |
| a.b.c.d  |       120 |
| a.b.c.d  |       120 |
| a.b.c.d  |       120 |
+----------+-----------+
4 rows in set (0.00 sec)

[umshastr@hod03]/export/umesh/mysql-5.7.6: ls -l 75510/a*
-rw-rw---- 1 umshastr common 158 Jan 16 11:27 75510/a.b.c.d
-rw-rw---- 1 umshastr common  40 Jan 16 11:27 75510/a.index
-rw-rw---- 1 umshastr common  56 Jan 16 10:30 75510/auto.cnf
[umshastr@hod03]/export/umesh/mysql-5.7.6: more 75510/a.index

./a.b.c.d
./a.b.c.d
./a.b.c.d
./a.b.c.d
[7 Dec 2017 12:02] Umesh Shastry
Bug #88788 marked as duplicate of this one
[11 Sep 2018 0:36] Andrew Dalgleish
Bug 88576 marked as a duplicate of this