replicate_wild_do_table和replicate-wild-ignore-table
来源:互联网 发布:环球英语怎么样知乎 编辑:程序博客网 时间:2024/05/22 01:33
使用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
+------+
|
+------+
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产生不同的影响,从而可能导致主从数据不一致。
阅读全文
0 0
- 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-wild-ignore-table
- 测试验证replicate-ignore-table参数作用
- MySQL复制,replicate-ignore-db模式下 如何正常同步
- 关于slave的replicate-ignore-db 参数 跨库问题
- 设置MySQL复制时,replicate-ignore-db模式下如何正常工作
- alter ignore table 添加unique key不生效的问题和临时解决方案
- 如何用mysqldump --ignore-table多个表
- alter ignore table add unique key
- alter ignore table 添加unique key
- 记1次未正确设置replicate-ignore-db参数导致MySQL主从同步异常的问题
- ignore ()
- Ignore
- Qt之ignore()和accept()
- git ignore 文件和文件夹
- qt ignore()和accept()函数
- sftp文件上传下载改名压缩解压
- orcl数据库后plsql登陆界面不显示数据库问题
- IOS 11 tableView 分页 执行reload() 时出现闪动
- 必须背单词、学语法?不,说一口地道的英语可以更容易!
- use opencv in android system
- replicate_wild_do_table和replicate-wild-ignore-table
- DBA之家
- Python编程从入门到实践:习题7-8~7-10
- 清空div和使div在同一行-------发现更大问题 jquery对象与dom对象
- 乌班图安装codeblocks时候遇到问题
- 教你如何在Mac系统下编译Android系统的源码
- 欧拉线性筛法求素数
- 页面加载loading适合于IE10以上及移动端
- AndroidStudio NDK调试dump内存数据到指定文件