首页 > 代码库 > mysql5.6 传统复制模式下1032和1062故障处理

mysql5.6 传统复制模式下1032和1062故障处理

一、环境

master     172.16.1.61      3307

slave      172.16.1.62      3307


二、检查环境

在master上检查

(root@127.0.0.1) [(none)]>show processlist\G
*************************** 1. row ***************************
     Id: 2
   User: root
   Host: localhost:42483
     db: NULL
Command: Query
   Time: 0
  State: init
   Info: show processlist
*************************** 2. row ***************************
     Id: 6
   User: repl
   Host: 172.16.1.62:35506
     db: NULL
Command: Binlog Dump
   Time: 84
  State: Master has sent all binlog to slave; waiting for binlog to be updated
   Info: NULL
2 rows in set (0.00 sec)

在slave上检查

(root@127.0.0.1) [(none)]>show slave status\G
*************************** 1. row ***************************
               Slave_IO_State: Waiting for master to send event
                  Master_Host: 172.16.1.61
                  Master_User: repl
                  Master_Port: 3307
                Connect_Retry: 60
              Master_Log_File: mybinlog3307.000007
          Read_Master_Log_Pos: 500
               Relay_Log_File: mysql-2-relay-bin.000003
                Relay_Log_Pos: 380
        Relay_Master_Log_File: mybinlog3307.000007
             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: 500
              Relay_Log_Space: 555
              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: 103307
                  Master_UUID: dab82de0-bf99-11e6-b441-000c29a11b1e
             Master_Info_File: /data/mysql/data3307/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: 
            Executed_Gtid_Set: deb3022d-bf9b-11e6-b44e-000c29fe5041:1
                Auto_Position: 0            #这里的值为0,表示是传统复制
1 row in set (0.00 sec)

三、模拟1062错误故障

1062错误是由于主键冲突引起的

在master创建一个表

#创建表t1
(root@127.0.0.1) [lyao]>create table t1(id int not null auto_increment, name varchar(30), primary key(id));
Query OK, 0 rows affected (0.37 sec)

(root@127.0.0.1) [lyao]>show tables;
+----------------+
| Tables_in_lyao |
+----------------+
| t1             |
+----------------+
1 row in set (0.00 sec)

(root@127.0.0.1) [lyao]>show create table t1;
+-------+----------------------------------------------------------------------------------------------------------------------------------------------------------+
| Table | Create Table                                                                                                                                             |
+-------+----------------------------------------------------------------------------------------------------------------------------------------------------------+
| t1    | CREATE TABLE `t1` (
  `id` int(11) NOT NULL AUTO_INCREMENT,
  `name` varchar(30) DEFAULT NULL,
  PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8 |
+-------+----------------------------------------------------------------------------------------------------------------------------------------------------------+
1 row in set (0.00 sec)

#在slave上查看结果
(root@127.0.0.1) [lyao]>show tables;
+----------------+
| Tables_in_lyao |
+----------------+
| t1             |
+----------------+
1 row in set (0.00 sec)

#在master上插入2条数据
(root@127.0.0.1) [lyao]>insert into t1(name) values(‘beijing‘);
Query OK, 1 row affected (0.31 sec)

(root@127.0.0.1) [lyao]>insert into t1(name) values(‘shenzhen‘);
Query OK, 1 row affected (0.02 sec)

(root@127.0.0.1) [lyao]>select * from t1;
+----+----------+
| id | name     |
+----+----------+
|  1 | beijing  |
|  2 | shenzhen |
+----+----------+
2 rows in set (0.00 sec)

#在slave上查看主从状态以及相应的表结果
(root@127.0.0.1) [lyao]>show slave status\G
*************************** 1. row ***************************
               Slave_IO_State: Waiting for master to send event
                  Master_Host: 172.16.1.61
                  Master_User: repl
                  Master_Port: 3307
                Connect_Retry: 60
              Master_Log_File: mybinlog3307.000007
          Read_Master_Log_Pos: 1055
               Relay_Log_File: mysql-2-relay-bin.000003
                Relay_Log_Pos: 935
        Relay_Master_Log_File: mybinlog3307.000007
             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: 1055
              Relay_Log_Space: 1110
              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: 103307
                  Master_UUID: dab82de0-bf99-11e6-b441-000c29a11b1e
             Master_Info_File: /data/mysql/data3307/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: 
            Executed_Gtid_Set: deb3022d-bf9b-11e6-b44e-000c29fe5041:1
                Auto_Position: 0
1 row in set (0.00 sec)

(root@127.0.0.1) [lyao]>select * from t1;
+----+----------+
| id | name     |
+----+----------+
|  1 | beijing  |
|  2 | shenzhen |
+----+----------+
2 rows in set (0.01 sec)
#结果表示一切正常

从上面的结果看出结果一切正常的,现在我们来模拟主键冲突的错误

#在slave上插入一条数据
(root@127.0.0.1) [lyao]>insert into t1(name) values(‘hangzhou‘);
Query OK, 1 row affected (0.31 sec)

#查看表结果
(root@127.0.0.1) [lyao]>select * from t1;
+----+----------+
| id | name     |
+----+----------+
|  1 | beijing  |
|  2 | shenzhen |
|  3 | hangzhou |
+----+----------+
3 rows in set (0.00 sec)

#查看主从状态结果,没有任何错误
(root@127.0.0.1) [lyao]>show slave status\G
*************************** 1. row ***************************
               Slave_IO_State: Waiting for master to send event
                  Master_Host: 172.16.1.61
                  Master_User: repl
                  Master_Port: 3307
                Connect_Retry: 60
              Master_Log_File: mybinlog3307.000007
          Read_Master_Log_Pos: 1055
               Relay_Log_File: mysql-2-relay-bin.000003
                Relay_Log_Pos: 935
        Relay_Master_Log_File: mybinlog3307.000007
             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: 1055
              Relay_Log_Space: 1110
              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: 103307
                  Master_UUID: dab82de0-bf99-11e6-b441-000c29a11b1e
             Master_Info_File: /data/mysql/data3307/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: 
            Executed_Gtid_Set: deb3022d-bf9b-11e6-b44e-000c29fe5041:1
                Auto_Position: 0
1 row in set (0.00 sec)

#现在在master上插入一条语句name=‘shanghai‘的值
(root@127.0.0.1) [lyao]>select * from t1;
+----+----------+
| id | name     |
+----+----------+
|  1 | beijing  |
|  2 | shenzhen |
+----+----------+
2 rows in set (0.00 sec)

(root@127.0.0.1) [lyao]>insert into t1(name) values(‘shanghai‘);
Query OK, 1 row affected (0.01 sec)

(root@127.0.0.1) [lyao]>select * from t1;
+----+----------+
| id | name     |
+----+----------+
|  1 | beijing  |
|  2 | shenzhen |
|  3 | shanghai |
+----+----------+
3 rows in set (0.00 sec)

#在slave上查看表结果
(root@127.0.0.1) [lyao]>select * from t1;
+----+----------+
| id | name     |
+----+----------+
|  1 | beijing  |
|  2 | shenzhen |
|  3 | hangzhou |            #这条记录还是之前的,新的数据并没有同步过来
+----+----------+
3 rows in set (0.00 sec)

#查看主从状态
(root@127.0.0.1) [lyao]>show slave status\G
*************************** 1. row ***************************
               Slave_IO_State: Waiting for master to send event
                  Master_Host: 172.16.1.61
                  Master_User: repl
                  Master_Port: 3307
                Connect_Retry: 60
              Master_Log_File: mybinlog3307.000007
          Read_Master_Log_Pos: 1255
               Relay_Log_File: mysql-2-relay-bin.000003
                Relay_Log_Pos: 935
        Relay_Master_Log_File: mybinlog3307.000007
             Slave_IO_Running: Yes
            Slave_SQL_Running: No            #SQL线程已经停止
              Replicate_Do_DB: 
          Replicate_Ignore_DB: 
           Replicate_Do_Table: 
       Replicate_Ignore_Table: 
      Replicate_Wild_Do_Table: 
  Replicate_Wild_Ignore_Table: 
                   Last_Errno: 1062        #1062状态
                   Last_Error: Could not execute Write_rows event on table lyao.t1; Duplicate entry ‘3‘ for key ‘PRIMARY‘, Error_code: 1062; handler error HA_ERR_FOUND_DUPP_KEY; the event‘s master log mybinlog3307.000007, end_log_pos 1224
                 Skip_Counter: 0
          Exec_Master_Log_Pos: 1055
              Relay_Log_Space: 1310
              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: 1062
               Last_SQL_Error: Could not execute Write_rows event on table lyao.t1; Duplicate entry ‘3‘ for key ‘PRIMARY‘, Error_code: 1062; handler error HA_ERR_FOUND_DUPP_KEY; the event‘s master log mybinlog3307.000007, end_log_pos 1224
  Replicate_Ignore_Server_Ids: 
             Master_Server_Id: 103307
                  Master_UUID: dab82de0-bf99-11e6-b441-000c29a11b1e
             Master_Info_File: /data/mysql/data3307/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: 161212 16:48:57
               Master_SSL_Crl: 
           Master_SSL_Crlpath: 
           Retrieved_Gtid_Set: 
            Executed_Gtid_Set: deb3022d-bf9b-11e6-b44e-000c29fe5041:1
                Auto_Position: 0
1 row in set (0.00 sec)


#从上面的结果能看出,slave上表t1中id=3的值存在引起的。
(root@127.0.0.1) [lyao]>select * from t1 where id=3;
+----+----------+
| id | name     |
+----+----------+
|  3 | hangzhou |
+----+----------+
1 row in set (0.00 sec)
#这条结果真的存在,但是这条数据不是我们要的,我们可以考虑删除该语句,恢复主从同步
#如果这条语句需要保留可以考虑在master上插入一条语句解决问题

#这里我们采用删除该语句来恢复主从同步
(root@127.0.0.1) [lyao]>select * from t1;
+----+----------+
| id | name     |
+----+----------+
|  1 | beijing  |
|  2 | shenzhen |
|  3 | hangzhou |
+----+----------+
3 rows in set (0.00 sec)


(root@127.0.0.1) [lyao]>select * from t1;
+----+----------+
| id | name     |
+----+----------+
|  1 | beijing  |
|  2 | shenzhen |
+----+----------+
2 rows in set (0.00 sec)

#重新启动sql_thread线程
(root@127.0.0.1) [lyao]>start slave sql_thread;
Query OK, 0 rows affected (0.02 sec)

#查看主从状态
(root@127.0.0.1) [lyao]>show slave status\G
*************************** 1. row ***************************
               Slave_IO_State: Waiting for master to send event
                  Master_Host: 172.16.1.61
                  Master_User: repl
                  Master_Port: 3307
                Connect_Retry: 60
              Master_Log_File: mybinlog3307.000007
          Read_Master_Log_Pos: 1255
               Relay_Log_File: mysql-2-relay-bin.000003
                Relay_Log_Pos: 1135
        Relay_Master_Log_File: mybinlog3307.000007
             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: 1255
              Relay_Log_Space: 1310
              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: 103307
                  Master_UUID: dab82de0-bf99-11e6-b441-000c29a11b1e
             Master_Info_File: /data/mysql/data3307/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: 
            Executed_Gtid_Set: deb3022d-bf9b-11e6-b44e-000c29fe5041:1
                Auto_Position: 0
1 row in set (0.00 sec)

以上结果显示恢复正常


四、模拟1032错误故障

1032错误主要是由于记录不存在引起的

#在master上查看表t1的结果
(root@127.0.0.1) [lyao]>select * from t1;
+----+----------+
| id | name     |
+----+----------+
|  1 | beijing  |
|  2 | shenzhen |
|  3 | shanghai |
+----+----------+
3 rows in set (0.01 sec)

#在slave查看表t1的结果
(root@127.0.0.1) [lyao]>select * from t1;
+----+----------+
| id | name     |
+----+----------+
|  1 | beijing  |
|  2 | shenzhen |
|  3 | shanghai |
+----+----------+
3 rows in set (0.00 sec)

#在slave上查看主从状态,结果正常
(root@127.0.0.1) [lyao]>show slave status\G
*************************** 1. row ***************************
               Slave_IO_State: Waiting for master to send event
                  Master_Host: 172.16.1.61
                  Master_User: repl
                  Master_Port: 3307
                Connect_Retry: 60
              Master_Log_File: mybinlog3307.000007
          Read_Master_Log_Pos: 1255
               Relay_Log_File: mysql-2-relay-bin.000003
                Relay_Log_Pos: 1135
        Relay_Master_Log_File: mybinlog3307.000007
             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: 1255
              Relay_Log_Space: 1310
              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: 103307
                  Master_UUID: dab82de0-bf99-11e6-b441-000c29a11b1e
             Master_Info_File: /data/mysql/data3307/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: 
            Executed_Gtid_Set: deb3022d-bf9b-11e6-b44e-000c29fe5041:1
                Auto_Position: 0
1 row in set (0.00 sec)

#在slave上从t1表中删除id=3的值,并查看主从状态,一切正常
(root@127.0.0.1) [lyao]>delete from t1 where id=3;
Query OK, 1 row affected (0.01 sec)

(root@127.0.0.1) [lyao]>select * from t1;
+----+----------+
| id | name     |
+----+----------+
|  1 | beijing  |
|  2 | shenzhen |
+----+----------+
2 rows in set (0.00 sec)

(root@127.0.0.1) [lyao]>show slave status\G
*************************** 1. row ***************************
               Slave_IO_State: Waiting for master to send event
                  Master_Host: 172.16.1.61
                  Master_User: repl
                  Master_Port: 3307
                Connect_Retry: 60
              Master_Log_File: mybinlog3307.000007
          Read_Master_Log_Pos: 1255
               Relay_Log_File: mysql-2-relay-bin.000003
                Relay_Log_Pos: 1135
        Relay_Master_Log_File: mybinlog3307.000007
             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: 1255
              Relay_Log_Space: 1310
              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: 103307
                  Master_UUID: dab82de0-bf99-11e6-b441-000c29a11b1e
             Master_Info_File: /data/mysql/data3307/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: 
            Executed_Gtid_Set: deb3022d-bf9b-11e6-b44e-000c29fe5041:1
                Auto_Position: 0
1 row in set (0.00 sec)


#在master上将id=3的数据删除掉
(root@127.0.0.1) [lyao]>delete from t1 where id=3;
Query OK, 1 row affected (0.32 sec)

(root@127.0.0.1) [lyao]>select * from t1;
+----+----------+
| id | name     |
+----+----------+
|  1 | beijing  |
|  2 | shenzhen |
+----+----------+
2 rows in set (0.00 sec)

#在slave上查看主从状态,可以看到已经显示1032错误状态
(root@127.0.0.1) [lyao]>show slave status\G
*************************** 1. row ***************************
               Slave_IO_State: Waiting for master to send event
                  Master_Host: 172.16.1.61
                  Master_User: repl
                  Master_Port: 3307
                Connect_Retry: 60
              Master_Log_File: mybinlog3307.000007
          Read_Master_Log_Pos: 1455
               Relay_Log_File: mysql-2-relay-bin.000003
                Relay_Log_Pos: 1135
        Relay_Master_Log_File: mybinlog3307.000007
             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: 1032
                   Last_Error: Could not execute Delete_rows event on table lyao.t1; Can‘t find record in ‘t1‘, Error_code: 1032; handler error HA_ERR_KEY_NOT_FOUND; the event‘s master log mybinlog3307.000007, end_log_pos 1424
                 Skip_Counter: 0
          Exec_Master_Log_Pos: 1255
              Relay_Log_Space: 1510
              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: 1032
               Last_SQL_Error: Could not execute Delete_rows event on table lyao.t1; Can‘t find record in ‘t1‘, Error_code: 1032; handler error HA_ERR_KEY_NOT_FOUND; the event‘s master log mybinlog3307.000007, end_log_pos 1424
  Replicate_Ignore_Server_Ids: 
             Master_Server_Id: 103307
                  Master_UUID: dab82de0-bf99-11e6-b441-000c29a11b1e
             Master_Info_File: /data/mysql/data3307/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: 161212 17:17:51
               Master_SSL_Crl: 
           Master_SSL_Crlpath: 
           Retrieved_Gtid_Set: 
            Executed_Gtid_Set: deb3022d-bf9b-11e6-b44e-000c29fe5041:1
                Auto_Position: 0
1 row in set (0.00 sec)


#在master上查看binlog日志文件
[root@mysql-1 ~]# mysqlbinlog --base64-output=decode-rows -v /data/mysql/data3307/mybinlog3307.000007 --start-position=1255 --stop-position=1424
/*!50530 SET @@SESSION.PSEUDO_SLAVE_MODE=1*/;
/*!40019 SET @@session.max_insert_delayed_threads=0*/;
/*!50003 SET @OLD_COMPLETION_TYPE=@@COMPLETION_TYPE,COMPLETION_TYPE=0*/;
DELIMITER /*!*/;
# at 1255
#161212 17:17:51 server id 103307  end_log_pos 1327 CRC32 0xaefdd0b1 	Query	thread_id=2	exec_time=0	error_code=0
SET TIMESTAMP=1481534271/*!*/;
SET @@session.pseudo_thread_id=2/*!*/;
SET @@session.foreign_key_checks=1, @@session.sql_auto_is_null=0, @@session.unique_checks=1, @@session.autocommit=1/*!*/;
SET @@session.sql_mode=1075838976/*!*/;
SET @@session.auto_increment_increment=1, @@session.auto_increment_offset=1/*!*/;
/*!\C utf8 *//*!*/;
SET @@session.character_set_client=33,@@session.collation_connection=33,@@session.collation_server=33/*!*/;
SET @@session.lc_time_names=0/*!*/;
SET @@session.collation_database=DEFAULT/*!*/;
BEGIN
/*!*/;
# at 1327
#161212 17:17:51 server id 103307  end_log_pos 1375 CRC32 0xdf4dd67b 	Table_map: `lyao`.`t1` mapped to number 70
# at 1375
#161212 17:17:51 server id 103307  end_log_pos 1424 CRC32 0xc1aaef42 	Delete_rows: table id 70 flags: STMT_END_F
### DELETE FROM `lyao`.`t1`
### WHERE
###   @1=3
###   @2=‘shanghai‘
DELIMITER ;
# End of log file            #这里的语句是引起1032的SQL语句
ROLLBACK /* added by mysqlbinlog */;
/*!50003 SET COMPLETION_TYPE=@OLD_COMPLETION_TYPE*/;
/*!50530 SET @@SESSION.PSEUDO_SLAVE_MODE=0*/;


#跳过这个sql语句
(root@127.0.0.1) [lyao]>set global sql_slave_skip_counter = 1;
Query OK, 0 rows affected (0.00 sec)


#重新启动sql_thread线程
(root@127.0.0.1) [lyao]>start slave sql_thread; 
Query OK, 0 rows affected (0.02 sec)


#查看主从状态,故障解决
(root@127.0.0.1) [lyao]>show slave status\G
*************************** 1. row ***************************
               Slave_IO_State: Waiting for master to send event
                  Master_Host: 172.16.1.61
                  Master_User: repl
                  Master_Port: 3307
                Connect_Retry: 60
              Master_Log_File: mybinlog3307.000007
          Read_Master_Log_Pos: 1455
               Relay_Log_File: mysql-2-relay-bin.000003
                Relay_Log_Pos: 1335
        Relay_Master_Log_File: mybinlog3307.000007
             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: 1455
              Relay_Log_Space: 1510
              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: 103307
                  Master_UUID: dab82de0-bf99-11e6-b441-000c29a11b1e
             Master_Info_File: /data/mysql/data3307/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: 
            Executed_Gtid_Set: deb3022d-bf9b-11e6-b44e-000c29fe5041:1
                Auto_Position: 0
1 row in set (0.00 sec)


本文出自 “ly36843运维” 博客,请务必保留此出处http://ly36843.blog.51cto.com/3120113/1881990

mysql5.6 传统复制模式下1032和1062故障处理