Question

I just configure 2 mySQL servers for a MASTER-MASTER replication. I choose the RBR replication for some reason.

My congifuration on the server ONE :

#replication
server-id=1
binlog_do_db = db1
binlog_ignore_db = db2
log-bin="C:/ProgramData/MySQL/my56"
auto_increment_increment = 2
auto_increment_offset = 1
binlog_format=ROW
replicate_do_db=db1

and on the server TWO :

#replication
server-id=2
binlog_do_db = db1
log-bin="C:/ProgramData/MySQL/my56"
auto_increment_increment = 2
auto_increment_offset = 2
binlog_format=ROW
replicate_do_db=db1

With this, the replication works.

For example, on server ONE, if I execute :

USE db1;
INSERT INTO db1.table1 values (foo,bar);

It's works on the server TWO.

If on server ONE I execute :

USE db1;
INSERT INTO second_db.table2 values (foo,bar);

The insert is not execute on the server TWO, it's good.

If on server ONE I execute :

CREATE table db1.tableFoo(id INT NOT NULL AUTO_INCREMENT PRIMARY KEY);

The create table is not execute on the server TWO, it's good because I choose the Row-Based replication, so I have to manualy execute the CREATE STATEMENT on server TWO. It's what I want.

Now, there is my problem :

If on the server ONE I execute :

USE db1;
CREATE table db1.tableFoo(id INT NOT NULL AUTO_INCREMENT PRIMARY KEY);

The CREATE TABLE is execute on the server TWO, it's NOT good ! Normally with the Row-Based Replication the CREATE ORDER is not replicated.

Worst, if after the USE db1; if create a table in another database, the CREATE TABLE is replicated on my server TWO, and my slave is aborted on the server TWO because de database doesn't exist...

Do you have any idea ? I dont want any CREATE / ALTER / CREATE USER ... send to my replication even if I use à USE db1;

I based my work on the mySQL documentation, especially this one : http://dev.mysql.com/doc/refman/5.6/en/replication-options-binary-log.html

Thank you and merry Xmas !

Was it helpful?

Solution

DDL statements are always logged using statement-based replication, regardless of whether you've chosen RBR or not. As a result, the default (current) database is important when you execute CREATE TABLE statements.

From http://dev.mysql.com/doc/refman/5.6/en/replication-options-binary-log.html#option_mysqld_binlog-do-db :

DDL statements such as CREATE TABLE and ALTER TABLE are always logged as statements, without regard to the logging format in effect, so the following statement-based rules for --binlog-do-db always apply in determining whether or not the statement is logged.

...Only those statements are written to the binary log where the default database (that is, the one selected by USE) is db_name.

This suggests that the behavior you observe is expected, although it is a bit odd.

If possible, I'd suggest that you USE an unreplicated DB (for example mysql) before executing DDL that you do not want to replicate in your application.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top