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

一、环境

master     172.16.1.61      3307

slave      172.16.1.62      3307

二、检查环境

在master上检查

([email protected]) [(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上检查

([email protected]) [(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
([email protected]) [lyao]>create table t1(id int not null auto_increment, name varchar(30), primary key(id));
Query OK, 0 rows affected (0.37 sec)

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

([email protected]) [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上查看结果
([email protected]) [lyao]>show tables;
+----------------+
| Tables_in_lyao |
+----------------+
| t1             |
+----------------+
1 row in set (0.00 sec)

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

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

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

#在slave上查看主从状态以及相应的表结果
([email protected]) [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)

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

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

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

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

#查看主从状态结果,没有任何错误
([email protected]) [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‘的值
([email protected]) [lyao]>select * from t1;
+----+----------+
| id | name     |
+----+----------+
|  1 | beijing  |
|  2 | shenzhen |
+----+----------+
2 rows in set (0.00 sec)

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

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

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

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

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

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

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

#查看主从状态
([email protected]) [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的结果
([email protected]) [lyao]>select * from t1;
+----+----------+
| id | name     |
+----+----------+
|  1 | beijing  |
|  2 | shenzhen |
|  3 | shanghai |
+----+----------+
3 rows in set (0.01 sec)

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

#在slave上查看主从状态,结果正常
([email protected]) [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的值,并查看主从状态,一切正常
([email protected]) [lyao]>delete from t1 where id=3;
Query OK, 1 row affected (0.01 sec)

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

([email protected]) [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的数据删除掉
([email protected]) [lyao]>delete from t1 where id=3;
Query OK, 1 row affected (0.32 sec)

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

#在slave上查看主从状态,可以看到已经显示1032错误状态
([email protected]) [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日志文件
[[email protected] ~]# 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 @[email protected]@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 [email protected]_COMPLETION_TYPE*/;
/*!50530 SET @@SESSION.PSEUDO_SLAVE_MODE=0*/;

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

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

#查看主从状态,故障解决
([email protected]) [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)
时间: 2024-10-14 02:26:25

mysql5.6 传统复制模式下1032和1062故障处理的相关文章

【MySQL】MySQL5.7传统复制切换为GTID复制

赞赏支持 [MySQL]MySQL5.7传统复制切换为GTID复制 前言:最近还是在做MariaDB10.1.12升级为MySQL5.7的升级方案,其中有一个环节涉及到传统复制到GTID复制的在线切换,本文就介绍下如何是现在线切换. 一.参数解析 下面对GTID_MODE变量如下解释: 值 解释 OFF 新事务是非GTID, Slave只接受不带GTID的事务,传送来GTID的事务会报错 OFF_PERMISSIVE 新事务是非GTID, Slave即接受不带GTID的事务也接受带GTID的事务

不同复制模式下,如何忽略某些binlog事件

在MySQL复制中,如果slave节点上遇到错误,比如数据不存在或者主键冲突等错误时,想要忽略这些错误,可以采用以下几种方法: 1.未启用GTID模式时 只需通过设定 SQL_SLAVE_SKIP_COUNTER 的值,即可忽略一些复制事件.例如: #需要先关闭SLAVE服务 [email protected] [test]> STOP SLAVE; #忽略N个事件(event),通常一个SQL是一个事件 [email protected] [test]> SET SQL_SLAVE_SKIP

mysql5.6传统复制改为基于GTID多线程复制

1.必须主备库两个的数据是一致的,也就是说当前从库没有数据延迟的情况.并且主库不能再有数据更新的情况.备库停止slave线程:stop slave; 主库:show master status; 备库:show slave status; 观察备库的Relay_Master_Log_File和主库的File一样,备库的Exec_Master_Log_Pos和主库的Position一样即可. 2.记下主库此时的file和position信息 3.修改主备库的my.cnf配置,增加参数配置如下: g

Oracle 环境下 GoldenGate 集成抽取(Integrated Capture)模式与传统抽取模式(Classic Capture)间的切换

检查抽取进程模式 在 GGSCI 环境下,执行类似如下语句查看特定进程的状态. GGSCI> info <Group_Name> 其中,<Group_Name> 为进程名称.例如:下图所示 EPUBADM 进程抽取模式为集成抽取模式(Integrated Capture) 例如:下图所示 ETEST 进程抽取模式为传统抽取模式(Classic Capture) 由传统抽取(Classic Capture)模式升级至集成抽取(Integrated Capture)模式 1.升级

MariaDB 10 Slave Crash-Safe需转为GTID复制模式

之前写了一篇<MySQL5.6 crash-safe replication> ,但在Mariadb10.0.X和10.1.X上不支持relay_log_info_repository = TABLE参数,官网建议用GTID复制模式代替传统复制模式,传统复制模式是不支持Slave Crash-Safe的. 在mysql库下,会有一张gtid_slave_pos表(在安装初始化时,就已经是innodb引擎) START TRANSACTION; -- Statement 1 -- ... -- 

Mysql半同步复制模式说明 - 运维小结

MySQL主从复制包括异步模式.半同步模式.GTID模式以及多源复制模式,默认是异步模式 (如之前详细介绍的mysql主从复制).所谓异步模式指的是MySQL 主服务器上I/O thread 线程将二进制日志写入binlog文件之后就返回客户端结果,不会考虑二进制日志是否完整传输到从服务器以及是否完整存放到从服务器上的relay日志中,这种模式一旦主服务(器)宕机,数据就可能会发生丢失. 异步模式是一种基于偏移量的主从复制,实现原理是:主库开启binlog功能并授权从库连接主库,从库通过chan

MySQL 半同步复制模式说明及配置示例 - 运维小结

MySQL主从复制包括异步模式.半同步模式.GTID模式以及多源复制模式,默认是异步模式 (如之前详细介绍的mysql主从复制).所谓异步模式指的是MySQL 主服务器上I/O thread 线程将二进制日志写入binlog文件之后就返回客户端结果,不会考虑二进制日志是否完整传输到从服务器以及是否完整存放到从服务器上的relay日志中,这种模式一旦主服务(器)宕机,数据就可能会发生丢失. 异步模式是一种基于偏移量的主从复制,实现原理是: 主库开启binlog功能并授权从库连接主库,从库通过cha

5.1 vim介绍 5.2 vim颜色显示和移动光标 5.3 vim一般模式下移动光标 5.4 vim一般模式下复制、剪切和粘贴

5.1 vim介绍 5.2 vim颜色显示和移动光标 5.3 vim一般模式下移动光标 5.4 vim一般模式下复制.剪切和粘贴 5.1 vim介绍 vim 是 vi的一个升级版本 vim 是带有颜色显示的 再试下vim 命令 [[email protected] ~]# vi /etc/passwd[[email protected] ~]# vim /etc/passwd-bash: vim: 未找到命令 [[email protected] ~]# yum install -y vim-e

MySQL5.7不停业务将传统复制变更为GTID复制

由于GTID的优势,我们需要将传统基于file-pos的复制更改为基于GTID的复制,如何在线变更成为我们关心的一个点,如下为具体的方法: 目前我们有一个传统复制下的M-S结构: port 3301 master port 3302 slave master上(3301): [zejin] 3301>select * from t_users; +----+------+ | id | name | +----+------+ | 1 | hao | | 2 | zhou | +----+---