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日誌文件
[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語句
([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)


發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章