mysql主从同步部分库_MySQL主从同步部分库跨库问题排查分析

MySQL主从同步部分库跨库问题排查分析

问题:使用复制是设置Replicate_Do_DB参数发现跨库操作时从库数据不更新

1设置从库的replicate_do_db = test

2主库的sql语句是跨库的insert在test7上插入数据到test.a的表上。

use test7;

937D8D8F5C2B403BAD98216E59F244CC

3主库数据更新后查看从库信息发现数据并没有插入

7683F736246F4758B37D1B140852CF78

4原因是mysql在执行sql前检查的当前默认库,所以跨库的sql语句不会被执行。

解决方案:

1使用参数replicate-wild-ignore-table=test.%

主库插入数据

D186624F62F24BDB9E127FF739030CF5

从库查看数据

69D9331F94574C35968CD2B5E9951303

----------2使用复制的组合过滤规则:replicate-do-db和replicate-do-table两个参数的过滤规则-------------暂时测试失败

参数说明

Replicate_Do_DB :

The effects of this option depend on whether statement-based or row-based replication is in use.

Statement-based replication.Tell the slave SQL thread to restrict replication to statements where the default database (that is, the one selected byUSE) is db_name. To specify more than one database, use this option multiple times, once for each database; however, doing so doesnotreplicate cross-database statements such asUPDATE some_db.some_table SET foo='bar' while a different database (or no database) is selected.

Warning

To specify multiple databases youmustuse multiple instances of this option. Because database names can contain commas, if you supply a comma separated list then the list will be treated as the name of a single database

·

replicate-do-db =db_name告诉从库sql线程限制复制sql语句,只复制默认的数库,多个数据库可以使用","

·

跨库sql不被执行的原因:“检查默认的数据库”行为是从sql语句中很难得知是否复制。sql进程检查的只是默认的数据库,而不是所有的数据

·

o

—replicate-ignore-db =db_name

o

意义与replicate-do-db =db_name相反是告诉从库数据库sql进程忽略指定的数据库,不进行任何复制。

USE prices;

UPDATE sales.january SET amount=amount+1000;

TheUPDATEstatementisreplicated in such a case because--replicate-ignore-dbapplies only to the default database (determined by theUSEstatement). Because the sales database was specified explicitly in the statement, the statement has not been filtered. However, when using row-based replication, theUPDATEstatement's effects arenotpropagated to the slave, and the slave's copy of the sales.january table is unchanged; in this instance,--replicate-ignore-db=salescausesallchanges made to tables in the master's copy of the sales database to be ignored by the slave.

同样是因为“检查默认的数据库”导致被忽略的数据库数据更新

·

replicate-do-table =db_name.tbl_name

·

告诉从库sql进程仅复制指定的表,指定多个表多次使用这个选项。 这个选项适用于跨库的更新和默认的数据库更新,

·

·

This option affects only statements that apply to tables. It does not affect statements that apply only to other database objects, such as stored routines. To filter statements operating on stored routines, use one or more of the

·

·

·

o

replicate-ignore-table =db_name.tbl_name

o

告诉从库sql进程不复制指定的表,指定多个表多次使用这个选项。 这个选项适用于跨库的更新和默认的数据库更新,

o

·

replicate-wild-do-table =db_name.tbl_name

·

从库的sql进程复制任何更新表的操作到指定的数据库名和表名,模式可以包含‘%’和“——”通配符,like模式匹配符的操作。适用于跨库操作

这个选项适用于表、视图和触发器。它并不适用于存储过程和函数,或事件。 过滤语句后面的对象上的操作,

This option applies to tables, views, and triggers. It does not apply to stored procedures and functions, or events. To filter statements operating on the latter objects, use one or more of the

·

replicate-wild-ignore-table =db_name.tbl_name

·

从库的sql进程不复制任何更新表的操作到指定的数据库名和表名,模式可以包含‘%’和“——”通配符,like模式匹配符的操作。

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值