replicate_wild_do_table和replicate-wild-ignore-table
2017-11-21 11:59
399 查看
使用replicate_do_db和replicate_ignore_db时有隐患。很容易造成主从数据不一致的情况。并且增加代码开发人员的负担。
所以应该在从库上尽可能的使用replicate_wild_do_table=DB_NAME.%或replicate_wild_ignore_table=DB_NAME.%
隐患如下:参考网址:http://blog.sina.com.cn/s/blog_747f4c1d0102w9pp.html
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=DB_NAME.%或replicate_wild_ignore_table=DB_NAME.%
隐患如下:参考网址:http://blog.sina.com.cn/s/blog_747f4c1d0102w9pp.html
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产生不同的影响,从而可能导致主从数据不一致。
相关文章推荐
- 做Mysql主从时,注意使用replicate_wild_do_table和replicate-wild-ignore-table
- mysql跨库复制: replicate_wild_do_table和replicate-wild-ignore-table
- 做Mysql主从时,注意使用replicate_wild_do_table和replicate-wild-ignore-table
- 做Mysql主从同步过滤时,应使用replicate_wild_do_table和replicate_wild_ignore_table参数
- mysql跨库复制: replicate_wild_do_table和replicate-wild-ignore-table
- 做Mysql主从时,注意使用replicate_wild_do_table和replicate-wild-ignore-table
- 做Mysql主从时,注意使用replicate_wild_do_table和replicate-wild-ignore-table【转】
- 做MySQL主从时,注意使用replicate_wild_do_table和replicate-wild-ignore-table
- 做Mysql主从时,注意使用replicate_wild_do_table和replicate-wild-ignore-table
- 使用replicate-rewrite-db 实现复制映射 + Replicate_Wild_Do_Table实现复制过滤
- replicate-wild-ignore-table
- replicate_do_db和repalicate_wild_do_table跨库同步问题
- 通过replicate-wild-do-table解决replicate-do-db的一些问题
- mysql之replicate_do_table/replicate_ingore_table/replicate_wide_do_table/replicate_wide_ingore_table
- 小心使用replicate_do_db和replicate_ignore_db
- 测试验证replicate-ignore-table参数作用
- 小心使用replicate_do_db和replicate_ignore_db
- 小心使用replicate_do_db和replicate_ignore_db
- 小心使用replicate_do_db和replicate_ignore_db
- 小心使用replicate_do_db和replicate_ignore_db