Mysql master-slave replication makes no sence

master-slave-replicationMySQLreplication

I have the following values in my.cnf settings in a simple Master -> Slave setup:

# MASTER my.cnf:
server-id = 1
log_bin = /var/log/mysql/mysql-bin.log
binlog_format=ROW
binlog_do_db = db2
max_binlog_cache_size = 2G
binlog_cache_size = 32K
max_binlog_stmt_cache_size = 2G
binlog_stmt_cache_size = 32K
max_binlog_size = 100M
expire_logs_days=3

# SLAVE my.cnf
server-id = 2
log_bin = /var/log/mysql/mysql-bin.log
relay-log = /var/log/mysql/mysql-relay-bin.log
binlog_format=ROW
replicate-wild-do-table=db2.%
max_binlog_cache_size = 2G
binlog_cache_size = 32K
max_binlog_stmt_cache_size = 2G
binlog_stmt_cache_size = 32K
max_binlog_size = 100M
expire_logs_days=3

The MySQL documentation states that in row-based replication the USE database is ignored and only the changed database is taken under consideration. However I've noticed the following behavior:

USE db1;
CREATE TABLE db2.Fake (field1 int,field2 int);

This is not replicated to Slave.

When I change the USE to db2 the replication works.
Am I missing something here ?

Best Answer

Am I missing something here ?

sure, just few row above:

For example, 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.