In the mysqlbinlog utility documentation, the --rewrite-db=name
option has the following explanation
Filtering (e.g. with --database=name ) happens AFTER the database rewrites have been performed.
However, my tests show that the filtering with the --database
option happens BEFORE the --rewrite-db
option is applied.
I reproduced the issue in the following way: I created a database db1
with a table t1
that contains one column c1
. Binlog format = ROW
.
CREATE DATABASE db1;
use db1;
CREATE TABLE t1 (c1 varchar(255));
Then I executed the following command:
FLUSH LOGS;
Made an insert into the table
INSERT INTO t1 (c1) VALUES (`row in db1.t1`);
Executed the command again
FLUSH LOGS;
I use the command below (the --vv
parameter decrypts the commands) to check what is extracted from the binlogs:
mysqlbinlog mysql-bin.000033 --rewrite-db='db1->new_db_name' --database='new_db_name' -vv
Only comments are output, no INSERT
commands. However, if I specify the name db1
in the --database
parameter, then INSERT
commands will be displayed:
mysqlbinlog mysql-bin.000033 --rewrite-db='db1->new_db_name' --database='db1' -vv
output:
...
...
BINLOG '
eI98YxMBAAAANgAAABwCAAAAADMAAAAAAAEAC25ld19kYl9uYW1lAAJ0MQABDwL8AwFyNVlH
eI98YxcBAAAAMQAAAE0CAAAAADMAAAAAAAEAAf/+DQByb3cgaW4gZGIxLnQxmq6ESw==
'/*!*/;
### INSERT INTO `new_db_name`.`t1`
### SET
### @1='row in db1.t1' /* VARSTRING(1020) meta=1020 nullable=1 is_null=0 */
...
...
Thus, it turns out that mysqlbinlog
first filters the binlog file with the --database
parameter and only then makes replacements with the --rewrite-db
parameter, which contradicts the documentation.
I tested similar scenarios for MySQL(no MariaDB), and it works as it should, the filtering is run AFTER the replacements.
Do I understand correctly that this is an error in the documentation? Or am I misunderstanding something?