(转)使用参数SQL_SLAVE_SKIP_COUNTER处理mysql slave同步错误讨论
使用参数SQL_SLAVE_SKIP_COUNTER处理mysql slave同步错误讨论
本文链接地址:http://blog.chinaunix.net/uid-31396856-id-5753206.html
本文讨论使用sql_slave_skip_counter 来使sql 线程跳过遇到错误的event记录
案例如下:
数据库数据无法同步,检查同步状态
MariaDB [(none)]> show slave status\G
*************************** 1. row ***************************
Slave_IO_State: Waiting for master to send event
Master_Host: 172.16.21.28
Master_User: repl
Master_Port: 3306
Connect_Retry: 60
Master_Log_File: master-bin.000010
Read_Master_Log_Pos: 137752106
Relay_Log_File: relay-bin.000004
Relay_Log_Pos: 670
Relay_Master_Log_File: master-bin.000009
Slave_IO_Running: Yes
Slave_SQL_Running: No
Replicate_Do_DB:
Replicate_Ignore_DB:
Replicate_Do_Table:
Replicate_Ignore_Table:
Replicate_Wild_Do_Table:
Replicate_Wild_Ignore_Table:
Last_Errno: 1008
Last_Error: Error 'Can't drop database 'emodb'; database doesn't exist' on query. Default database: 'emodb'. Query: 'drop database emodb'
Skip_Counter: 0
Exec_Master_Log_Pos: 1379
Relay_Log_Space: 320095465
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: 1008
Last_SQL_Error: Error 'Can't drop database 'emodb'; database doesn't exist' on query. Default database: 'emodb'. Query: 'drop database emodb'
Replicate_Ignore_Server_Ids:
Master_Server_Id: 28
1 row in set (0.00 sec)
发现在执行删除emodb的操作时候,发现备库不存在这个库。至于为什么备库已经没有了emo数据库的原因按下不表,继续处理往下:
首选关闭同步:
MariaDB [(none)]> stop slave;
Query OK, 0 rows affected (0.00 sec)
跳过这个错误的操作
MariaDB [(none)]> SET GLOBAL SQL_SLAVE_SKIP_COUNTER = 1;
Query OK, 0 rows affected (0.00 sec)
然后开启同步,检查同步是否能够正常进行。
MariaDB [(none)]>
MariaDB [(none)]> start slave;
Query OK, 0 rows affected (0.00 sec)
MariaDB [(none)]> show slave status\G
*************************** 1. row ***************************
Slave_IO_State: Waiting for master to send event
Master_Host: 172.16.21.28
Master_User: repl
Master_Port: 3306
Connect_Retry: 60
Master_Log_File: master-bin.000010
Read_Master_Log_Pos: 137752106
Relay_Log_File: relay-bin.000004
Relay_Log_Pos: 761
Relay_Master_Log_File: master-bin.000009
Slave_IO_Running: Yes
Slave_SQL_Running: No
Replicate_Do_DB:
Replicate_Ignore_DB:
Replicate_Do_Table:
Replicate_Ignore_Table:
Replicate_Wild_Do_Table:
Replicate_Wild_Ignore_Table:
Last_Errno: 1007
Last_Error: Error 'Can't create database 'confluence'; database exists' on query. Default database: 'confluence'. Query: 'create database confluence DEFAULT CHARACTER SET utf8'
Skip_Counter: 0
Exec_Master_Log_Pos: 1470
Relay_Log_Space: 320096038
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: 1007
Last_SQL_Error: Error 'Can't create database 'confluence'; database exists' on query. Default database: 'confluence'. Query: 'create database confluence DEFAULT CHARACTER SET utf8'
Replicate_Ignore_Server_Ids:
Master_Server_Id: 28
1 row in set (0.00 sec)
按照上面的处理办法,继续处理
MariaDB [(none)]> stop slave;
Query OK, 0 rows affected (0.00 sec)
MariaDB [(none)]> SET GLOBAL SQL_SLAVE_SKIP_COUNTER = 1;
Query OK, 0 rows affected (0.00 sec)
MariaDB [(none)]>
MariaDB [(none)]>
MariaDB [(none)]> start slave;
Query OK, 0 rows affected (0.00 sec)
MariaDB [(none)]> show slave status\G
*************************** 1. row ***************************
Slave_IO_State: Waiting for master to send event
Master_Host: 172.16.21.28
Master_User: repl
Master_Port: 3306
Connect_Retry: 60
Master_Log_File: master-bin.000010
Read_Master_Log_Pos: 137752106
Relay_Log_File: relay-bin.000004
Relay_Log_Pos: 57581283
Relay_Master_Log_File: master-bin.000009
Slave_IO_Running: Yes
Slave_SQL_Running: Yes
Replicate_Do_DB:
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: 57581992
Relay_Log_Space: 320096611
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: 83248
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: 28
1 row in set (0.00 sec)
okay了,继续观察
MariaDB [(none)]> show slave status\G
*************************** 1. row ***************************
Slave_IO_State: Waiting for master to send event
Master_Host: 172.16.21.28
Master_User: repl
Master_Port: 3306
Connect_Retry: 60
Master_Log_File: master-bin.000010
Read_Master_Log_Pos: 137752193
Relay_Log_File: relay-bin.000008
Relay_Log_Pos: 617
Relay_Master_Log_File: master-bin.000010
Slave_IO_Running: Yes
Slave_SQL_Running: Yes
Replicate_Do_DB:
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: 137752193
Relay_Log_Space: 1190
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: 28
1 row in set (0.00 sec)
MariaDB [(none)]> show databases;
+--------------------+
| Database |
+--------------------+
| information_schema |
| confluence |
| dbyang |
| mysql |
| performance_schema |
| temp |
+--------------------+
6 rows in set (0.00 sec)
在测试下
MariaDB [(none)]> show databases;
+--------------------+
| Database |
+--------------------+
| information_schema |
| confluence |
| mysql |
| performance_schema |
| temp |
+--------------------+
5 rows in set (0.00 sec)
MariaDB [(none)]> show slave status\G
*************************** 1. row ***************************
Slave_IO_State: Waiting for master to send event
Master_Host: 172.16.21.28
Master_User: repl
Master_Port: 3306
Connect_Retry: 60
Master_Log_File: master-bin.000010
Read_Master_Log_Pos: 137752278
Relay_Log_File: relay-bin.000008
Relay_Log_Pos: 702
Relay_Master_Log_File: master-bin.000010
Slave_IO_Running: Yes
Slave_SQL_Running: Yes
Replicate_Do_DB:
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: 137752278
Relay_Log_Space: 1275
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: 28
1 row in set (0.00 sec)
主从虽然开始同步,但是还需要检查主从数据是否一致,但这不在本文讨论范围内。
说明:
1、参数SQL_SLAVE_SKIP_COUNTER=n 是跳过n个事务继续进入后面的事务同步。这里是主库在进行drop database的操作的同步到slave,slave已经没有drop的database,这种情况下进行跳过,不影响主从的不一致。
2、如果轻易的使用容易造成主从不一致,需要谨慎的使用,使用前应该具体问题具体分析。
3、如果需要使用SQL_SLAVE_SKIP_COUNTER,需要明确跳过的event是什么操作;
4、如果使用了参数SQL_SLAVE_SKIP_COUNTER,需要检查主从数据的一致性。
---the end
(转)使用参数SQL_SLAVE_SKIP_COUNTER处理mysql slave同步错误讨论的更多相关文章
- Mysql slave 同步错误解决
涉及知识点 mysql 主从同步 ,参考: MySQL数据库设置主从同步 mysqlbin log查看, 参考:MySQL的binlog日志 解决slave报错, 参考: Backup stopped ...
- replicate-do-db参数引起的MySQL复制错误及处理办法
replicate-do-db配置在MySQL从库的my.cnf文件中,可以指定只复制哪个库的数据.但是这个参数有个问题就是主库如果在其他的schema环境下操作,其binlog不会被从库应用,从而出 ...
- mysql主从同步错误恢复
Mysql主从同步集群在生成环境使用过程中,如果主从服务器之间网络通信条件差或者数据库数据量非常大,容易导致MYSQL主从同步延迟. MYSQL主从产生延迟之后,一旦主库宕机,会导致部分数据没有及时同 ...
- 处理一则MySQL Slave环境出现ERROR 1201 (HY000): Could not initialize master info structure的案例
mysql> start slave; ERROR (HY000): Slave failed to initialize relay log info structure from the r ...
- mysql主从同步错误解决和Slave_IO_Running: NO
1.出现错误提示. Slave I/O: error connecting to master 'backup@192.168.1.x:3306' - retry-time: 60 retries: ...
- canal mysql slave
[mysqld] log-bin=mysql-bin #添加这一行就ok binlog-format=ROW #选择row模式 server_id=1 #配置mysql replaction需要定义, ...
- xtrabackup备份方式搭建一个mysql slave
以前mysql搭建新备库都是在现在业务较小的备库上停止同步或停止数据库,然后拷贝数据库到新备库,配置好新备库后,再开启同步或数据库.然而,这次没有空闲备库用来搭新备库.需要从一个业务繁忙的数据库中搭建 ...
- 使用Percona Xtrabackup创建MySQL slave库
一.使用Percona Xtrabackup创建MySQL slave库 MySQL Server 版本: Server version: 5.7.10-log MySQL Community Ser ...
- 普通用户Mysql 5.6.13 主从,主主及nagios的mysql slave监控
Master:192.168.209.19 Slave:192.168.209.20 mysql版本:mysql5.6.13 1. 以root身份创建普通用户,如mysql,并创建mysql安装目录: ...
随机推荐
- poj3013Big Chrismas Tree——树转换spfa
题目:http://poj.org/problem?id=3013 看似生成树,实则最短路,可以将题意转化为点权*根到此点的边权和(最短路使其最小). 代码如下: #include<iostre ...
- WPF 后台触发 Validate UI‘s Element
wpf中有validateRule类, 用于界面元素的验证, 如何后台去控制validateRule呢? 1. UI层要binding写好的ValidateRule,分为Binding和MultiBi ...
- 《TCP/IP详解卷一:协议》数据链路层(一)
版权声明:本文为博主原创文章,转载请标注转载链接,谢谢. 目录(?)[+] 引言 在TCP/IP协议族中,链路层主要有三个目的: 为IP模块发送和接收IP数据报. 为ARP模块 ...
- Python之模块介绍
模块介绍 模块,是用一些代码实现的某个功能的代码集合. 类似与函数式编程和面向过程编程,函数式编程则完成一个功能,其他代码用来调用,提供了代码的重用性和代码间的耦合.对于一个复杂的功能,可能需要多个函 ...
- cookie,sessionStorage 和 localStorage
1.三者之间的区别 cookie是网站为了标示用户身份而储存在用户本地终端(Client Side)上的数据(通常经过加密). cookie数据始终在同源的http请求中携带(即使不需要),记会在浏览 ...
- Oracle数据库获取一行记录中某几个字段的最大值/最小值函数
在数据库的开发过程中,我们可能会遇到这样的需求,获取一行记录中某几个字段的最大值或者是最小值,oracle给我们提供了解决这种需求的函数,如下所示: greatest(col1, col2, co ...
- C#窗体上绘制矩形
先上效果图 鼠标三个事件 private void Form1_MouseDown(object sender, MouseEventArgs e) { //记录开始点 this.mousedown ...
- Will you still need me?
ON FRIDAY, the National Bureau of Statistics announced that China's working-age population shrank la ...
- uva 12452 Plants vs. Zombies HD SP (树DP)
Problem I: Plants vs. Zombies HD Super Pro Plants versus Zombies HD Super Pro is a game played not a ...
- IE各栏的截图说明
工具栏 包括 状态栏 命令栏 菜单栏 收藏栏 IE工具 > 工具栏 > 状态栏 有状态栏显示 无状态栏显示 菜单栏 快捷键 alt 可以快速展示 菜单栏 ,查看 ...