使用参数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同步错误讨论的更多相关文章

  1. Mysql slave 同步错误解决

    涉及知识点 mysql 主从同步 ,参考: MySQL数据库设置主从同步 mysqlbin log查看, 参考:MySQL的binlog日志 解决slave报错, 参考: Backup stopped ...

  2. replicate-do-db参数引起的MySQL复制错误及处理办法

    replicate-do-db配置在MySQL从库的my.cnf文件中,可以指定只复制哪个库的数据.但是这个参数有个问题就是主库如果在其他的schema环境下操作,其binlog不会被从库应用,从而出 ...

  3. mysql主从同步错误恢复

    Mysql主从同步集群在生成环境使用过程中,如果主从服务器之间网络通信条件差或者数据库数据量非常大,容易导致MYSQL主从同步延迟. MYSQL主从产生延迟之后,一旦主库宕机,会导致部分数据没有及时同 ...

  4. 处理一则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 ...

  5. mysql主从同步错误解决和Slave_IO_Running: NO

    1.出现错误提示. Slave I/O: error connecting to master 'backup@192.168.1.x:3306' - retry-time: 60  retries: ...

  6. canal mysql slave

    [mysqld] log-bin=mysql-bin #添加这一行就ok binlog-format=ROW #选择row模式 server_id=1 #配置mysql replaction需要定义, ...

  7. xtrabackup备份方式搭建一个mysql slave

    以前mysql搭建新备库都是在现在业务较小的备库上停止同步或停止数据库,然后拷贝数据库到新备库,配置好新备库后,再开启同步或数据库.然而,这次没有空闲备库用来搭新备库.需要从一个业务繁忙的数据库中搭建 ...

  8. 使用Percona Xtrabackup创建MySQL slave库

    一.使用Percona Xtrabackup创建MySQL slave库 MySQL Server 版本: Server version: 5.7.10-log MySQL Community Ser ...

  9. 普通用户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安装目录: ...

随机推荐

  1. L95

    The children squealed with delight when they saw the puppy.The signal will be converted into digital ...

  2. 【译】在ES6中如何优雅的使用Arguments和Parameters

    原文地址:how-to-use-arguments-and-parameters-in-ecmascript-6 ES6是最新版本的ECMAScript标准,而且显著的改善了JS里的参数处理.我们现在 ...

  3. HihoCoder1654: XY游戏([Offer收割]编程练习赛39)(好久没写搜索)(已经超级简短了)

    描述 如下图所示,在4x4的棋盘上有X和Y两种棋子各若干枚:O表示空格. OXXY YOOX XOOY XOXX 小Hi每次可以选择任意一枚棋子,将它移动到上下左右相邻的空格中. 小Hi想知道最少移动 ...

  4. P2762 [网络流24题]太空飞行计划问题(最小割)

    地址 最大权闭合子图裸题,不说了吧,求方案就是把s集遍历一遍. 错误记录:dfs那块忘判断残量了,11分×1. #include<cstdio> #include<iostream& ...

  5. DS:目录

    ylbtech-DS:目录 1.返回顶部   2.返回顶部   3.返回顶部   4.返回顶部   5.返回顶部     6.返回顶部   作者:ylbtech出处:http://ylbtech.cn ...

  6. 生成分布式随机ID

    经测试,最快的一种 public class Generator { // should be between 40 (34 years) and 42 (139 years) ; // should ...

  7. Primer回顾 标准库类型

    string类型的输入操作符: 1.读取并忽略开头所有的空白字符(如空格,换行符,制表符). 2.读取字符直至再次遇到空白字符,读取终止.   用getline读取整行文本 getline.接受两个参 ...

  8. centos6.5安装gtk开发环境

    0.说明 由于 centos 默认的桌面是 gnome 的,我们知道gnome 的依赖库就是 gtk,而 gtk 各个版本的差异性还是很大的,所以我们需要根据 centos 的不同版本选择和 cent ...

  9. eos表结构总结说明

    EOS6.0 WORKFLOW 表结构说明 流程定义表(WFProcessDefine) 名称 代码 描述 流程定义ID processDefID 主键 流程定义名称 processDefName 业 ...

  10. PCANet: A Simple Deep Learning Baseline for Image Classification?----中文翻译

    一 摘要 在本文中,我们提出了一个非常简单的图像分类深度学习框架,它主要依赖几个基本的数据处理方法:1)级联主成分分析(PCA);2)二值化哈希编码;3)分块直方图.在所提出的框架中,首先通过PCA方 ...