(转)使用参数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

原文地址:https://www.cnblogs.com/liujiacai/p/8144886.html

时间: 2024-08-01 04:17:05

(转)使用参数SQL_SLAVE_SKIP_COUNTER处理mysql slave同步错误讨论的相关文章

mysql主从同步错误解决

mysql主从同步错误解决和Slave_IO_Running: NO 一: Slave I/O: error connecting to master '[email protected]:3306' - retry-time: 60  retries: 86400, Error_code: 1045 解决方法 从服务器上删除掉所有的二进制日志文件,包括一个数据目录下的master.info文件和hostname-relay-bin开头的文件. master.info::记录了Mysql主服务器

处理一则MySQL Slave环境出现ERROR 1201 (HY000): Could not initialize master info structure的案例

mysql> start slave; ERROR 1872 (HY000): Slave failed to initialize relay log info structure from the repository 处理一则MySQL Slave环境出现ERROR 1201 (HY000): Could not initialize master info structure的案例. 冷备份方式复制一份新的slave,初始化参数中已经修改了相关文件路径及server_id等关联参数. 但

Mysqldump参数大全 这 些参数 不同于 mysql 的那些参数(下边文章开头有链接) :2 种类型的参数含义是不一样的

Mysqldump参数大全  这 些参数 不同于 mysql 的那些参数  :2 种类型的参数含义是不一样的 Mysqldump参数大全(参数来源于mysql5.5.19源码) 参数 参数说明 --all-databases , -A 导出全部数据库. mysqldump -uroot -p --all-databases --all-tablespaces , -Y 导出全部表空间. mysqldump -uroot -p --all-databases --all-tablespaces -

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

1.出现错误提示. Slave I/O: error connecting to master '[email protected]:3306' - retry-time: 60  retries: 86400, Error_code: 1045 解决方法 从服务器上删除掉所有的二进制日志文件,包括一个数据目录下的master.info文件和hostname-relay-bin开头的文件. master.info::记录了Mysql主服务器上的日志文件和记录位置.连接的密码. 2.出现错误提示

xtrabackup备份方式搭建mysql slave

以前mysql搭建新备库都是在现在业务较小的备库上停止同步或停止数据库,然后拷贝数据库到新备库,配置好新备库后,再开启同步或数据库.然而,这次没有空闲备库用来搭新备库.  需要从一个业务繁忙的数据库中搭建一个新备库,对系统延时要求比较高,所以同步和数据库都不能停.所以我们用了percona的 xtrabackup备份工具.  因为这个备份要作为备库,所以用了–slave-info参数,备份完成后会生成一个对应主库的binlog日志的文件,用于配置同步.为了保证数据一致性,使用了–slave-in

使用参数innodb_file_per_table支持MySQL InnoDB表数据共享空间自动收缩

http://heylinux.com/archives/2367.html http://blog.csdn.net/ywh147/article/details/8996022 使用过MySQL的同学,刚开始接触最多的莫过于MyISAM表引擎了,这种引擎的数据库会分别创建三个文件:表结构.表索引.表数据空间.我们可以将某个数据库目录直接迁移到其他数据库也可以正常工作.然而当你使用InnoDB的时候,一切都变了.InnoDB 默认会将所有的数据库InnoDB引擎的表数据存储在一个共享空间中:i

innobackupex 备份数据搭建 MySQL Slave

简介: 数据量比较大时,使用 innobackupex 备份数据新增 MySQL Slave 节点. 安装 innobackupex 工具,我这里写过一次:http://www.cnblogs.com/wangxiaoqiangs/p/5961413.html 场景: A -> B -> C -> D -> E 一.增加节点 C # 由于有从库 B ,所以我们去 B 上面执行备份 shell > innobackupex --user=xx --password=xx --s

MySQL slave状态之Seconds_Behind_Master

在MySQL的主从环境中,我们能够通过在slave上运行show slave status来查看slave的一些状态信息,当中有一个比較重要的參数Seconds_Behind_Master.那么你是否明确它的真正含义以及它是怎么计算的呢? 在之前我一直误以为Seconds_Behind_Master是表示slave比master落后多少,假设这个值为0的表示主从已经处于一致了(在非同步模式下,如今官方最多也仅仅在5.5中添加?了半同步复制).可是近期我最终认识到之前的错误理解.首先我们须要明确的

一次Mysql slave库恢复实战记录

状况描述:今天登录一个mysql数据库slave节点主机发现/var/lib/mysql下存放大量的mysql-relay-bin文件,最早的文件创建日期甚至是2018年,我记得在slave同步完master的日志操作记录后,会删除这些文件(默认设置不会删除,我记错了).查看mysql slave状态,发现如下报错: mysql> show slave status\G; *************************** 1. row ***************************