mysql参数:binlog-do-db和replicate-do-db


   
mysql主从复制的两个参数

binlog-do-db:指定mysql的binlog日志记录哪个db

实验:
主库:
binlog-do-db=test
binlog-do-db=xiaobin
root@[mysql]>show variables like '%binlog_format';
+---------------+-----------+
| Variable_name |Value    |
+---------------+-----------+
| binlog_format | STATEMENT |
+---------------+-----------+
1 row in set (0.00 sec)

root@[mysql]>use mysql;
Database changed

root@[mysql]>create table test.dd (id int);
Query OK, 0 rows affected (0.00 sec)

root@[mysql]>select * from test.dd;
Empty set (0.02 sec)


从库:
(testing)root@localhost [test]> use test;
Database changed

(testing)root@localhost [test]> show tables;
Empty set (0.01 sec)

----------------------------------------------

主库:
root@[mysql]>use xiaobin;
Reading table information for completion of table and columnnames
You can turn off this feature to get a quicker startup with-A

Database changed
root@[xiaobin]>create table test.dd (id int);
Query OK, 0 rows affected (0.02 sec)

从库:
(testing)root@localhost [test]> show tables;
+----------------+
| Tables_in_test |
+----------------+
|dd            |
+----------------+
1 row in set (0.00 sec)

结论:在binlog_format=STATEMENT时,在用usedbname的格式下,如果dbname没有在binlog-do-db里,DDL和DML语句都不会被记录在binlog里。即使指定具体的test.dd;

————————————————————————————————————————

主库:
root@[(none)]>show variables like '%binlog_format';
+---------------+-------+
| Variable_name | Value |
+---------------+-------+
| binlog_format | ROW   |
+---------------+-------+
1 row in set (0.00 sec)

root@[(none)]>use mysql
Reading table information for completion of table and columnnames
You can turn off this feature to get a quicker startup with-A

Database changed
root@[mysql]>create table test.dd (id int);
Query OK, 0 rows affected (0.01 sec)

从库:
(testing)root@localhost [test]> show tables;
Empty set (0.02 sec)
---------

主库:
root@[mysql]>insert into test.dd values(11);
Query OK, 1 row affected (0.00 sec)

root@[mysql]>commit;
Query OK, 0 rows affected (0.01 sec)

从库:
(testing)root@localhost [test]> select * from dd;
+------+
| id   |
+------+
|   11 |
+------+
1 row in set (0.00 sec)

结论:在row模式下,在用usedbname的格式下,如果dbname没有在binlog-do-db里,DDL语句都不会被记录在binlog里。即使指定具体的test.dd;DML语句会记录。

————————————————————————————————————————————

主库:
root@[(none)]>show variables like '%binlog_format';
+---------------+-------+
| Variable_name | Value |
+---------------+-------+
| binlog_format | MIXED |
+---------------+-------+
1 row in set (0.00 sec)

root@[(none)]>use mysql
Reading table information for completion of table and columnnames
You can turn off this feature to get a quicker startup with-A

Database changed
root@[mysql]>create table test.dd (id int);
Query OK, 0 rows affected (0.01 sec)

从库:
(testing)root@localhost [test]> show tables;
Empty set (0.02 sec)
---------
主库:
root@[mysql]>insert into test.dd values(11);
Query OK, 1 row affected (0.00 sec)

root@[mysql]>commit;
Query OK, 0 rows affected (0.01 sec)

从库:
(testing)root@localhost [test]> select * from dd;
Empty set (0.01 sec)

结论:在mixed模式下,在用usedbname的格式下,如果dbname没有在binlog-do-db里,DDL、DML语句都不会被记录在binlog里。即使指定具体的test.dd;

总结:
在有几个数据库的情况下
binlog-do-db=db1

use db1;
update db1.table1 set col1=10,db2.table2 set col2=10;
当使用statement模式时,两个修改都会被记录到binlog里;当使用row模式时,只有table1的修改会记录到binlog,table2不会记录。

use db4;
update db1.table1 set col1=10,db2.table2 set col2=10;
当使用statement模式时,两个修改都不会被记录到binlog里;当使用row模式时,只有table1的修改会记录到binlog,table2不会记录。




Replicate_Do_DB:参数是在slave上配置,指定slave要复制哪个库

Replicate-Do-DB=sales

use price;
update sales.february set amount=amount+100
当使用statement模式时,update语句将不会被复制到slave上;当使用row模式时,update语句会复制到slave上;


Replicate-Do-DB=db1

use db1;
update db1.table1 set col1=10,db2.table2 set col2=10;
当使用statement模式时,两个修改都会复制到slave上;当使用row模式时,只有table1的update语句会复制到slave上,table2不会复制。

use db4;
update db1.table1 set col1=10,db2.table2 set col2=10;
当使用statement模式时,两个修改都不会复制到slave上;当使用row模式时,只有table1的update语句会复制到slave上,table2不会复制。


建议在没有完全测试清楚的情况下,mysql复制的这几个选择性参数要慎用, 因为在 binlog_format不同的情况下,会对binlog产生不同的影响,从而可能导致主从数据不一致。
如果有需要,可以使用replicate-wild-do-table和Replicate-Ignore-Table代替。

你可能感兴趣的:(mysql)