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代替。

  • 0
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值