介绍

在5.7版本支持动态修改,之前的版本需要重启数据库:

STOP SLAVE SQL_THREAD;

CHANGE REPLICATION FILTER REPLICATE_IGNORE_DB=(demo);

START SLAVE SQL_THREAD;

问题描述

在主库执行语句,如果不使用use db;

创建新表的语句不会在从库执行,进而导致主从错误

场景复现

从库配置:

replicate-ignore-db = test

replicate-do-db = abc

主库操作:

22:29:04test>use test;

Database changed

22:30:26test>create table abc.t0417(id int,name varchar(20));

Query OK, 0 rows affected (0.08 sec)

22:31:37abc>use test;

Database changed

22:32:05test>insert into abc.t0417 values(1,'a');

Query OK, 1 row affected (0.02 sec)

从库状态,SQL线程出现报错:

22:31:07abc>show slave status \G

*************************** 1. row ***************************

Slave_IO_State: Waiting for master to send event

Master_Host: 192.168.136.128

Master_User: repl

Master_Port: 3306

Connect_Retry: 60

Master_Log_File: mysql-bin.000015

Read_Master_Log_Pos: 8478

Relay_Log_File: cptest-relay-bin.000007

Relay_Log_Pos: 1292

Relay_Master_Log_File: mysql-bin.000015

Slave_IO_Running: Yes

Slave_SQL_Running: No

Replicate_Do_DB: abc

Replicate_Ignore_DB: test

Replicate_Do_Table:

Replicate_Ignore_Table:

Replicate_Wild_Do_Table:

Replicate_Wild_Ignore_Table:

Last_Errno: 1146

Last_Error: Error executing row event: 'Table 'abc.t0417' doesn't exist'

Skip_Counter: 0

Exec_Master_Log_Pos: 8235

Relay_Log_Space: 1709

Until_Condition: None

Until_Log_File:

Until_Log_Pos: 0

Master_SSL_Allowed: No

Master_SSL_CA_File:

Master_SSL_CA_Path:

Master_SSL_Cert:

Master_SSL_Cipher:

Master_SSL_Key:

Seconds_Behind_Master: NULL

Master_SSL_Verify_Server_Cert: No

Last_IO_Errno: 0

Last_IO_Error:

Last_SQL_Errno: 1146

Last_SQL_Error: Error executing row event: 'Table 'abc.t0417' doesn't exist'

Replicate_Ignore_Server_Ids:

Master_Server_Id: 1

Master_UUID: 4ac80f6d-8063-11e7-9d63-000c291d913c

Master_Info_File: /data/mysql/mysql3309/master.info

SQL_Delay: 0

SQL_Remaining_Delay: NULL

Slave_SQL_Running_State:

Master_Retry_Count: 86400

Master_Bind:

Last_IO_Error_Timestamp:

Last_SQL_Error_Timestamp: 180416 22:32:20

Master_SSL_Crl:

Master_SSL_Crlpath:

Retrieved_Gtid_Set: 4ac80f6d-8063-11e7-9d63-000c291d913c:3609-3630

Executed_Gtid_Set: 4ac80f6d-8063-11e7-9d63-000c291d913c:1:3609-3629,

a1c747e9-4170-11e8-883f-000c29c6b279:1

Auto_Position: 0

1 row in set (0.00 sec)

解决问题

更改从库配置:

#replicate-ignore-db = test

#replicate-do-db = abc

replicate_wild_do_table = abc.%

replicate_wild_ignore_table = test.%

主库操作:

Welcome to the MySQL monitor. Commands end with ; or \g.

Your MySQL connection id is 65

Server version: 5.6.35-log Source distribution

Copyright (c) 2000, 2016, Oracle and/or its affiliates. All rights reserved.

Oracle is a registered trademark of Oracle Corporation and/or its

affiliates. Other names may be trademarks of their respective

owners.

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

caopeng@192.168.136.128 00:39:16(none)>use test;

Database changed

caopeng@192.168.136.128 00:39:32test>create table abc.test0417(id int,name varchar(20));

Query OK, 0 rows affected (0.17 sec)

caopeng@192.168.136.128 00:40:25test>insert into abc.test0417 values(1,'b');

Query OK, 1 row affected (0.11 sec)

从库状态:

root@localhost 00:39:06(none)>show slave status \G

*************************** 1. row ***************************

Slave_IO_State: Waiting for master to send event

Master_Host: 192.168.136.128

Master_User: repl

Master_Port: 3306

Connect_Retry: 60

Master_Log_File: mysql-bin.000015

Read_Master_Log_Pos: 9644

Relay_Log_File: cptest-relay-bin.000010

Relay_Log_Pos: 771

Relay_Master_Log_File: mysql-bin.000015

Slave_IO_Running: Yes

Slave_SQL_Running: Yes

Replicate_Do_DB:

Replicate_Ignore_DB:

Replicate_Do_Table:

Replicate_Ignore_Table:

Replicate_Wild_Do_Table: abc.%

Replicate_Wild_Ignore_Table: test.%

Last_Errno: 0

Last_Error:

Skip_Counter: 0

Exec_Master_Log_Pos: 9644

Relay_Log_Space: 945

Until_Condition: None

Until_Log_File:

Until_Log_Pos: 0

Master_SSL_Allowed: No

Master_SSL_CA_File:

Master_SSL_CA_Path:

Master_SSL_Cert:

Master_SSL_Cipher:

Master_SSL_Key:

Seconds_Behind_Master: 0

Master_SSL_Verify_Server_Cert: No

Last_IO_Errno: 0

Last_IO_Error:

Last_SQL_Errno: 0

Last_SQL_Error:

Replicate_Ignore_Server_Ids:

Master_Server_Id: 1

Master_UUID: 4ac80f6d-8063-11e7-9d63-000c291d913c

Master_Info_File: /data/mysql/mysql3309/master.info

SQL_Delay: 0

SQL_Remaining_Delay: NULL

Slave_SQL_Running_State: Slave has read all relay log; waiting for the slave I/O thread to update it

Master_Retry_Count: 86400

Master_Bind:

Last_IO_Error_Timestamp:

Last_SQL_Error_Timestamp:

Master_SSL_Crl:

Master_SSL_Crlpath:

Retrieved_Gtid_Set: 4ac80f6d-8063-11e7-9d63-000c291d913c:3609-3635

Executed_Gtid_Set: 4ac80f6d-8063-11e7-9d63-000c291d913c:1:3609-3635,

a1c747e9-4170-11e8-883f-000c29c6b279:1-6

Auto_Position: 0

1 row in set (0.00 sec)

root@localhost 00:40:54(none)>select * from abc.test0417;

+------+------+

| id | name |

+------+------+

| 1 | b |

+------+------+

1 row in set (0.00 sec)

总结

使用replicate_do_db和replicate_ignore_db两个参数时在主库操作需要使用use db;然后再进行其他操作

推荐使用replicate_wild_do_table,

replicate_wild_ignore_table

mysql replicate_do_db_关于replicate_do_db和replicate_ignore_db的坑相关推荐

  1. mysql replicate_mysql 复制参数replicate_do_db和replicate_ignore_db介绍

    演示环境: 1.MySQL5.7.24 二进制安装包 2.master库和slave库都是全新的环境进行配置 3.MySQL开启gtid 并且指定具体的数据库进行同步库 maser 库my.cnf配置 ...

  2. centos7恢复mysql数据库_MySQL数据库升级迁移填坑记

    原库:*.*.101.73/74 系统环境: Suse 12.4 MySQL: 5.7.29 新库:*.*.110.46/47 系统环境:CentOS7.7 64位 MySQL版本: 5.7.30 [ ...

  3. MySQL大表传输表空间的坑

    MySQL大表传输表空间的坑 最近刚帮业务线拆分完数据库, 源环境遗留了一张700G的大表, 虽说现在不用了, 但是业务方还是不希望删掉, 于是打算把这张表迁移到归档库, 这样有需要是还可以查询. 7 ...

  4. 警惕参数变化,MySQL 8.0 升级避免再次踩坑

    MySQL 8.0新特性专栏目录 <MySQL开发规范>过时了,视图查询性能提升了一万倍 你真的会用EXPLAIN么,SQL性能优化王者晋级之路 索引三剑客之降序索引和不可见索引 千呼万唤 ...

  5. mysql replicate_do_db_使用replicate-rewrite-db 实现复制映射 + Replicate_Wild_Do_Table实现复制过滤...

    实验环境:CentOS7.2 + MySQL5.7 node1(192.168.2.171)和node2(192.168.2.172) 为两台不同业务的MySQL服务器. 业务方有个需求,需要将nod ...

  6. 數據庫ORACLE轉MYSQL存儲過程遇到的坑~(總結)

    ORACLE數據庫轉MySQL數據庫遇到的坑 總結 最近在做Oracle轉mysql的工程,遇到的坑是真的多,尤其是存儲過程,以前都沒接觸過類似的知識,最近也差不多轉完了就總結一下.希望能幫到一些人( ...

  7. mysql allowmultiqueries=true_Mysql批量更新的一个坑-allowMultiQueries=true允许批量更新(转)...

    实际上,我们经常会遇到这样的需求,那就是利用Mybatis批量更新或者批量插入,但是,实际上即使Mybatis完美支持你的sql,你也得看看你说操作的数据库是否支持,而阿福,最近就遇到这样的一个坑. ...

  8. MySql Cluster 集成安装,Centos,坑点集锦

    2019独角兽企业重金招聘Python工程师标准>>> 坑点集锦 安装步骤->安装步骤 查看错误->错误集锦 节点作用->节点作用 测试结果->测试结果 [M ...

  9. mysql+vs检测不到_VS2017 + EF + MySQL 我使用过程中遇到的坑

    写在前面: 第一次使用MySQL连接VS的时候本着最新版的应该就是最好的,在MySQL官网下载了最新版的MySQL没有并且安装完成之后,使用MySQLHelper连接MySQL数据库也是正常的,也就没 ...

最新文章

  1. php解决 mysql_connect(): The mysql extension is deprecated and will be removed in the future: use mysq
  2. 网友:Java岗,自学一个月跳槽计算机视觉,其实入门很简单
  3. python计算多个模型在不同数据集上的预测概率、获取每个数据集上的最优模型、多个最优模型的ROC曲线进行对比分析
  4. 网络工程师人手必备!常用网络命令合集请收下
  5. [操作系统]从零开始的OS
  6. Java并发:线程共享变量可见性原理
  7. 被卡性能的时候要care数据类型(洛谷P5594TLE+RE的经历,Java语言描述)
  8. 华为再获90天“临时许可证” 可继续维护客户
  9. 快速格式化从pdf、caj论文中复制的文本格式(正则替换)
  10. VMware Workstation12安装win 7企业版激活
  11. 下载pyboard的flash中的驱动程序_如何安装爱普生打印机驱动程序
  12. python实现根据前序序列和中序序列求二叉树的后序序列
  13. 数学不好是原罪——高等数学笔记(汇总版)
  14. 向量空间模型(vector space model)
  15. pc微信多开hook版本3.2.1.123
  16. Rational Rose 2007 使用方法
  17. NVIDIA NCCL 源码学习(五)- 路径计算
  18. J2EE高级开发框架小课程之Spring框架2——Spring容器作用域,生命周期,Spring管理对象之间依赖关系
  19. 【c++入门(2)】邻项交换
  20. jmeter进行接口压力测试

热门文章

  1. FBI 树【普及-】
  2. java文本框添加单击事件,组合框和文本框的VBA动态数组单击事件
  3. CentOS8 配置本地yum源详细教程
  4. Win10系统下浏览器缓存怎么清理?
  5. suse ftp文件服务器搭建,SUSE下FTP服务器搭建
  6. 外卖探探新手操作详细教程
  7. linux桌面应用程序开发工具,极简桌面工具(uTools For Linux)
  8. 释放技术创新引擎,英特尔携手生态合作伙伴推动智慧零售蓬勃发展
  9. ubuntu20安装ukylin企业微信记录
  10. 希尔顿集团大中华区第500家酒店开业;Bose和沃尔沃汽车合作推出新款音响系统 | 美通企业日报...