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.

use db1;
CREATE TABLE t1 (c1 varchar(255));

Then I executed the following command:


Made an insert into the table

INSERT INTO t1 (c1) VALUES (`row in db1.t1`);

Executed the command again


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


### 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?

1 Answer 1


Looking at the code it seems --database option is applied to QUERY_EVENT/QUERY_COMPRESSED_EVENT just before print_use_statement uses the --rewrite-db.

With the TABLE_MAP_EVENT, --database is applied before --rewrite-db is applied to TABLE_MAP_EVENT.

So you are absolutely right, this is a documentation error. MariaDB's KB is editable if you'd like to change this.


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.