replicate-do-db参数引起的MySQL复制错误及处理办法
replicate-do-db配置在MySQL从库的my.cnf文件中,可以指定只复制哪个库的数据。但是这个参数有个问题就是主库如果在其他的schema环境下操作,其binlog不会被从库应用,从而出现异常。可以简单的测试一下 --replicate-do-db参数引起的MySQL复制错误,步骤如下。
从库的my.cnf中有如下配置:
replicate-do-db = maopaodb
首先在主库切换到test这个库并建立maopaodb下的一个表:
mysql> use test;
Database changed
mysql> create table maopaodb.test(id int,name varchar(10));
Query OK, 0 rows affected (0.09 sec)
mysql> use maopaodb;
Database changed
mysql> show tables;
+--------------------------+
| Tables_in_maopaodb |
+--------------------------+
......
| test |
......
+--------------------------+
32 rows in set (0.01 sec)
可见这个表在maopaodb下创建成功,而这时去从库查看,是没有这个表的,因为我们是在test这个库下操作的,而从库的--replicate-do-db指定了maopaodb,因此这些信息不会在从库被应用。
这时主库切换到maopaodb,并写入一条记录:
mysql> use maopaodb;
Database changed
mysql> insert into test values (1,'a');
Query OK, 1 row affected (0.01 sec)
从库这时就会报错了:
mysql> show slave status\G
*************************** 1. row ***************************
Slave_IO_State: Waiting for master to send event
Master_Host: 192.168.0.33
Master_User: repl
Master_Port: 3306
Connect_Retry: 60
Master_Log_File: mysql-bin.000010
Read_Master_Log_Pos: 93731745
Relay_Log_File: mysql-relay-bin.000008
Relay_Log_Pos: 5979038
Relay_Master_Log_File: mysql-bin.000010
Slave_IO_Running: Yes
Slave_SQL_Running: No
Replicate_Do_DB: maopaodb
Replicate_Ignore_DB:
Replicate_Do_Table:
Replicate_Ignore_Table:
Replicate_Wild_Do_Table:
Replicate_Wild_Ignore_Table:
Last_Errno: 1146
Last_Error: Error 'Table 'maopaodb.test' doesn't exist' on query. Default database: 'maopaodb'. Query: 'insert into test values (1,'a')'
Skip_Counter: 0
Exec_Master_Log_Pos: 93709288
Relay_Log_Space: 6001650
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 'Table 'maopaodb.test' doesn't exist' on query. Default database: 'maopaodb'. Query: 'insert into test values (1,'a')'
1 row in set (0.00 sec)
对于这种问题复制同步方面的问题,主要都是要在从库这边手动做一些动作,要么补充一些操作,要么跳过一些操作。我们看看如何跳过这个操作。
首先我们要从上边的报错信息关注到以下三点:
Relay_Master_Log_File: mysql-bin.000010
Skip_Counter: 0
Exec_Master_Log_Pos: 93709288
就是我们要明白是主库的哪个日志文件,和日志文件中报错的具体位置,而Skip_Counter参数就是我们要利用的东西。这里我们看到是mysql-bin.000010这个日志文件的93709288位置报错,那么就到主库看看这个位置到底是在执行什么东西:
mysql> SHOW BINLOG EVENTS in 'mysql-bin.000010' from 93709288;
+------------------+----------+------------+-----------+-------------+---------------------------------------------------------------------------------------------------------------------+
| Log_name | Pos | Event_type | Server_id | End_log_pos | Info |
+------------------+----------+------------+-----------+-------------+---------------------------------------------------------------------------------------------------------------------+
| mysql-bin.000010 | 93709288 | Query | 1 | 93709360 | BEGIN |
| mysql-bin.000010 | 93709360 | Query | 1 | 93709458 | use `maopaodb`; insert into test values (1,'a') |
| mysql-bin.000010 | 93709458 | Xid | 1 | 93709485 | COMMIT /* xid=28862936 */ |
| mysql-bin.000010 | 93709485 | Query | 1 | 93709557 | BEGIN |
| mysql-bin.000010 | 93709557 | Query | 1 | 93709723 | use `mogilefs`; UPDATE device SET mb_total = '9564', mb_used = '386', mb_asof = UNIX_TIMESTAMP() WHERE devid = '13' |
| mysql-bin.000010 | 93709723 | Xid | 1 | 93709750 | COMMIT /* xid=28863050 */
......
可见正是导致出错的这个insert语句,MySQL的binary log每个SQL执行实际上是由一些event组成的,我们这里要设置的就是要跳过的event的个数。本例中就是BEGIN、具体SQL语句和COMMIT这3个event,因此我们可以在从库上这样跳过这个语句:
mysql> SET GLOBAL SQL_SLAVE_SKIP_COUNTER = 3;
Query OK, 0 rows affected (0.00 sec)
然后开启同步,一切正常:
mysql> start slave;
Query OK, 0 rows affected (0.00 sec)
mysql> show slave status\G
*************************** 1. row ***************************
Slave_IO_State: Waiting for master to send event
Master_Host: 192.168.0.33
Master_User: repl
Master_Port: 3306
Connect_Retry: 60
Master_Log_File: mysql-bin.000010
Read_Master_Log_Pos: 93733865
Relay_Log_File: mysql-relay-bin.000008
Relay_Log_Pos: 6003615
Relay_Master_Log_File: mysql-bin.000010
Slave_IO_Running: Yes
Slave_SQL_Running: Yes
Replicate_Do_DB: maopaodb
Replicate_Ignore_DB:
Replicate_Do_Table:
Replicate_Ignore_Table:
Replicate_Wild_Do_Table:
Replicate_Wild_Ignore_Table:
Last_Errno: 0
Last_Error:
Skip_Counter: 0
Exec_Master_Log_Pos: 93733865
Relay_Log_Space: 6003770
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:
1 row in set (0.00 sec)
replicate-do-db参数引起的MySQL复制错误及处理办法的更多相关文章
- Atitit.软件GUIbutton与仪表盘--db数据库区--导入mysql sql错误的解决之道
Atitit.软件GUIbutton与仪表盘--db数据库区--导入mysql sql错误的解决之道 Keyword::截取文本文件后部分 查看提示max_allowed_packet限制 Targe ...
- Atitit.软件GUI按钮与仪表盘--db数据库区--导入mysql sql错误的解决之道
Atitit.软件GUI按钮与仪表盘--db数据库区--导入mysql sql错误的解决之道 Keyword::截取文本文件后部分 查看提示max_allowed_packet限制 Target Se ...
- MySQL复制错误1837的相关缺陷一例
故障现象 主从gtid报错,复制错误1837,这个复制故障可以说是第一次遇到. Last_Errno: 1837 Last_Error: Error 'When @@SESSION.GTID_NEXT ...
- MySQL常见错误及其解决办法
1.连接类 (1).问题:MySQL server has gone away 解决办法:出现该报错常见的原因是服务器超时了并且关闭了连接.缺省地,如果没有事情发生,服务器在 8个小时后关闭连接.如 ...
- [MySQL复制] SQL_ERROR 1032解决办法(non-gtid env)
一.缘由: 在主主同步的测试环境,由于业务侧没有遵循同一时间只写一个点的原则,造成A库上删除了一条数据,B库上在同时更新这条数据. 由于异步和网络延时,B的更新event先到达A端执行,造成A端找不到 ...
- MySQL复制错误 The slave I/O thread stopsbecause master and slave have equal MySQL server UUIDs; these UUIDs must bedifferent for replication to work 解析
在搭建Mysql主从复制时候,在执行完相关操作以后,通过命令查看是否主从复制成功的时候 show slave status\G; 在"Slave_SQL_Running_State" ...
- /var/lib/mysql/mysql.sock错误的解决办法
问题描述: 使用mysql -uroot -p登录出现找不到 /var/lib/mysql/mysql.sock或者被使用的问题. 可以用如下命令登录:mysql -p --socket=/tmp/m ...
- [MySQL复制异常]'Cannot execute statement: impossible to write to binary log since statement is in row format and BINLOG_FORMAT = STATEMENT.'
MySQL复制错误]Last_Errno: 1666 Last_Error: Error executing row event: 'Cannot execute statement: imposs ...
- 【转】[MySQL复制异常]Cannot execute statement: impossible to write to binary log since statement is in row for
MySQL复制错误]Last_Errno: 1666 Last_Error: Error executing row event: 'Cannot execute statement: imposs ...
随机推荐
- Add and Search Word - Data structure design
https://leetcode.com/problems/add-and-search-word-data-structure-design/ Design a data structure tha ...
- UVA 11401 - Triangle CountingTriangle Counting 数学
You are given n rods of length 1,2, . . . , n. You have to pick any 3 of them and build a triangle. ...
- 如何开启Centos6.4系统的SSH服务
无论是Centos6.4系统的虚拟电脑还是服务器,始终感觉直接在命令行中操作不方便:比如全选.复制.粘贴.翻页等等.比如服务器就需要在机房给服务器接上显示器.键盘才操作感觉更麻烦.所以就可借助SSH( ...
- redis系列之Redis应用场景
1 取最新N个数据的操作 比如典型的取你网站的最新文章,通过下面方式,我们可以将最新的5000条评论的ID放在Redis的List集合中,并将超出集合部分从数据库获取 1)使用LPUSH latest ...
- Centos环境下部署游戏服务器-编译
游戏服务器是在windows环境开发的,相关跨平台的东西在这里不谈了,只谈如何将Visual Studio 工程转换到Linux下编译.这里涉及到的软件分别为:Centos版本为6.4,Visual ...
- mongo中查询Array类型的字段中元素个数
I have a MongoDB collection with documents in the following format: { "_id" : ObjectId(&qu ...
- SIM卡
SIM卡是(Subscriber Identity Module 客户识别模块)的缩写 也称为用户身份识别卡.智能卡,GSM数字移动电话机必须装上此卡方能使用.在电脑芯片上存储了数字移动电话客户的信息 ...
- 详解TCP和UDP数据段的首部格式
TCP数据段的首部格式: 源端口号(16) 目的端口号(16) 序列号(32) 确认应答号(32) 数据偏移(4) 保留(6) 代码位(6) 窗口(16) 校验和(16) 紧急指针 选项(长度可变) ...
- springboot源码解析 - 构建SpringApplication
1 package com.microservice.framework; 2 3 import org.springframework.boot.SpringApplication; 4 impor ...
- marquee 笔记
页面的自动滚动效果,可由javascript来实现, 但是有一个html标签 - <marquee></marquee>可以实现多种滚动效果,无需js控制. 使用marquee ...