mysql> show slave status\G
*************************** 1. row *************************** Slave_IO_State: Waiting for master to send event Master_Host: 192.168.190.27 Master_User: repl Master_Port: 3306 Connect_Retry: 60 Master_Log_File: restoredb-bin.000013 Read_Master_Log_Pos: 2637 Relay_Log_File: restoredb2-relay-bin.000010 Relay_Log_Pos: 1059 Relay_Master_Log_File: restoredb-bin.000013 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: 1062 Last_Error: Could not execute Write_rows event on table liangdb.t_test_02; Duplicate entry '2' for key 'PRIMARY', Error_code: 1062; handler error HA_ERR_FOUND_DUPP_KEY; the event's master log restoredb-bin.000013, end_log_pos 2606 Skip_Counter: 0 Exec_Master_Log_Pos: 2362 Relay_Log_Space: 1991 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: NULLMaster_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 liangdb.t_test_02; Duplicate entry '2' for key 'PRIMARY', Error_code: 1062; handler error HA_ERR_FOUND_DUPP_KEY; the event's master log restoredb-bin.000013, end_log_pos 2606 Replicate_Ignore_Server_Ids: Master_Server_Id: 62 Master_UUID: 85f64e00-7a86-11e8-92cd-ee2079684cfe Master_Info_File: /data/mysql/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: 180724 16:46:36 Master_SSL_Crl: Master_SSL_Crlpath: Retrieved_Gtid_Set: Executed_Gtid_Set: Auto_Position: 0 Replicate_Rewrite_DB: Channel_Name: Master_TLS_Version: 1 row in set (0.00 sec) 注意上面有三个信息是我们需要的:Exec_Master_Log_Pos: 2362master log restoredb-bin.000013end_log_pos 2606 [root@restoredb mysql]# mysqlbinlog --base64-output="decode-rows" -v --start-position=2362 --stop-position=2606 restoredb-bin.000013 >liangguojun.log
[root@restoredb mysql]# cat liangguojun.log
/*!50530 SET @@SESSION.PSEUDO_SLAVE_MODE=1*/;/*!50003 SET @OLD_COMPLETION_TYPE=@@COMPLETION_TYPE,COMPLETION_TYPE=0*/;DELIMITER /*!*/;# at 2362#180724 16:46:46 server id 62 end_log_pos 2427 CRC32 0xe4e76605 Anonymous_GTID last_committed=sequence_number=7 rbr_only=yes/*!50718 SET TRANSACTION ISOLATION LEVEL READ COMMITTED*//*!*/;SET @@SESSION.GTID_NEXT= 'ANONYMOUS'/*!*/;# at 2427#180724 16:46:46 server id 62 end_log_pos 2502 CRC32 0xfe5c8054 Query thread_id=1261 exec_time=0 error_code=0SET TIMESTAMP=1532422006/*!*/;SET @@session.pseudo_thread_id=1261/*!*/;SET @@session.foreign_key_checks=1, @@session.sql_auto_is_null=0, @@session.unique_checks=1, @@session.autocommit=1/*!*/;SET @@session.sql_mode=268435456/*!*/;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 2502#180724 16:46:46 server id 62 end_log_pos 2560 CRC32 0x63793851 Table_map: `liangdb`.`t_test_02` mapped to number 416# at 2560#180724 16:46:46 server id 62 end_log_pos 2606 CRC32 0xd4c25867 Write_rows: table id 416 flags: STMT_END_F### INSERT INTO `liangdb`.`t_test_02`### SET### @1=2### @2='test'ROLLBACK /* added by mysqlbinlog */ /*!*/;SET @@SESSION.GTID_NEXT= 'AUTOMATIC' /* added by mysqlbinlog */ /*!*/;DELIMITER ;# End of log file/*!50003 SET COMPLETION_TYPE=@OLD_COMPLETION_TYPE*/;/*!50530 SET @@SESSION.PSEUDO_SLAVE_MODE=0*/;