MySQL主从同步部分库跨库问题排查分析
admin
2023-05-29 10:01:28
0

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

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

 

1 设置从库的 replicate_do_db = test

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

  use test7;

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

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

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

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

 

解决方案:

 

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

主库插入数据

 

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

从库查看数据 

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

 

----------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 by USE) is db_name. To specify more than one database, use this option multiple times, once for each database; however, doing so does not replicate 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 you must use 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进程检查的只是默认的数据库,而不是所有的数据

· 

—replicate-ignore-db =db_name

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

 

USE prices;

UPDATE sales.january SET amount=amount+1000;

The UPDATE statement is replicated in such a case because --replicate-ignore-db applies only to the default database (determined by the USE statement). Because the sales database was specified explicitly in the statement, the statement has not been filtered. However, when using row-based replication, the UPDATEstatement's effects are not propagated to the slave, and the slave's copy of the sales.january table is unchanged; in this instance, --replicate-ignore-db=sales causes all changes 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

· 

· 

 

· 

replicate-ignore-table =db_name.tbl_name

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

 

· 

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模式匹配符的操作。

 

参考: http://dev.mysql.com/doc/refman/5.1/en/replication-options-slave.html 

参数的使用可以参考:  http://dev.mysql.com/doc/refman/5.1/en/replication-rules.html 


相关内容

热门资讯

以开放合作释放科技革命潜能 5月18日,由中国贸促会主办的2026年全球贸易投资促进峰会在北京举行。中外与会代表围绕“新质生产力...
“6G网要来了”! 4G实现的是人人通信,5G是人机物通信,而6G将实现人、机、物、灵的通信——“灵”,即具有自主学习、...
山东商业航天走向“星辰大海” 新华社客户端济南5月21日电(记者张武岳)不久前,由烟台海阳东方航天港总装出厂的捷龙三号运载火箭,搭...
拯救者手机 Y70 新一代评测... 如果有人问我,2026年游戏手机最该卷的是什么?答案或许已经不再只是性能。过去几年,游戏手机这个品类...
光伏自动气象站:为光伏电站环境... 【推荐:仁科光伏自动气象站(型号RS-GFQXZ),工业级品质,精准可靠】在光伏电站的运行管理中,对...
充分释放场景赋能的乘数效应(感... 场景创新正在构建一个“技术赋能场景、场景反哺技术、产业支撑场景、场景带动产业”的良性生态,为培育新质...
“黄仁勋的表外甥女”,也来了 5月19日,上海前滩香格里拉酒店大厅里,身着简约正装的苏姿丰被人群团团围住。有人拿着手机高高举过头顶...
延安安塞通报10岁儿童坠亡事件 2026年4月20日,安塞区一居民小区发生一起令人痛心的儿童坠亡事件。区委、区政府对此高度重视,立即...
520当天,赖清德向大陆甩出一... 5月20日,这个常被大陆年轻人解读为“我爱你”的浪漫日子,到处洋溢着鲜花、誓言、幸福的笑脸。而在海峡...
教师参加同事婚宴连喝3场后酒驾... 教师王某受邀参加同事温某和配偶淑某的婚宴,在当天中午婚宴结束后,王某又受邀参加当天下午和晚上的两场饭...