5.6之前跳过失败事务命令:
mysql> set global sql_slave_skip_counter=1; --指定跳过一个事务
5.6版本GTID跳过失败事务操作步骤:
mysql> show slave status \G; *************************** 1. row *************************** Slave_IO_State: Waiting for master to send event Master_Host: 192.168.3.45 Master_User: slave Master_Port: 3306 Connect_Retry: 60 Master_Log_File: slave-bin.000029 Read_Master_Log_Pos: 1550 Relay_Log_File: master-relay-bin.000056 Relay_Log_Pos: 603 Relay_Master_Log_File: slave-bin.000029 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 Update_rows event on table mysql.user; Can't find record in 'user', Error_code: 1032; handler error HA_ERR_KEY_NOT_FOUND; the event's master log slave-bin.000029, end_log_pos 1344 Skip_Counter: 0 Exec_Master_Log_Pos: 763 Relay_Log_Space: 2809 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 Update_rows event on table mysql.user; Can't find record in 'user', Error_code: 1032; handler error HA_ERR_KEY_NOT_FOUND; the event's master log slave-bin.000029, end_log_pos 1344 Replicate_Ignore_Server_Ids: Master_Server_Id: 3 Master_UUID: 2d7ca199-4ad8-11e5-b592-080027f8dc35 Master_Info_File: /data/home/mysql2/mysql/data/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: 150922 13:06:09 Master_SSL_Crl: Master_SSL_Crlpath: Retrieved_Gtid_Set: 2d7ca199-4ad8-11e5-b592-080027f8dc35:3-5 Executed_Gtid_Set: 2d7ca199-4ad8-11e5-b592-080027f8dc35:1-3, 52b2b88e-5747-11e5-86a8-0800274bf022:1-1601492 Auto_Position: 1 1 row in set (0.00 sec)
因为该部署模式为主主复制,所以可以从出错的DB上查看slave状态,显示主库上3-5,而报错库只到1-3,所以,执行以下命令:
mysql> stop slave; Query OK, 0 rows affected (0.08 sec) mysql> set GTID_NEXT= '2d7ca199-4ad8-11e5-b592-080027f8dc35:3'; Query OK, 0 rows affected (0.00 sec) mysql> begin;commit; Query OK, 0 rows affected (0.00 sec) Query OK, 0 rows affected (0.00 sec) mysql> set gtid_next='AUTOMATIC'; Query OK, 0 rows affected (0.00 sec) mysql> start slave; Query OK, 0 rows affected (0.06 sec) mysql> show slave status \G; --查看是否有错,如果还没有跳过,则继续往下执行空事务跳过错误事务,直到SQL,IO进程均为yes即可
也可主库上查看binlog ,出错DB上会显示如下:
从库上:show slave status \G; --查看exec_master_log_pos 从库上执行master日志的位置
Exec_Master_Log_Pos: 763
到主库的binlog目录 :
mysqlbinlog slave-bin.000029 --start-position=763 进行next-gtid查看