接下来直接修改binlog文件,把Mats改成Matz。
#master_verify_checksum默认为0. master> SHOW BINLOG EVENTS FROM 261; +-------------------+-----+------------+-----------+-------------+-----------------------------------------------------------+ | Log_name | Pos | Event_type | Server_id | End_log_pos | Info | +-------------------+-----+------------+-----------+-------------+-----------------------------------------------------------+ | master-bin.000001 | 261 | Query | 1 | 333 | BEGIN | | master-bin.000001 | 333 | Intvar | 1 | 365 | INSERT_ID=1 | | master-bin.000001 | 365 | Query | 1 | 477 | USE `test`; INSERT INTO t1(name) VALUES ('Matz'),('Luis') | | master-bin.000001 | 477 | Query | 1 | 550 | COMMIT | +-------------------+-----+------------+-----------+-------------+-----------------------------------------------------------+ 4 ROWS IN SET (0.00 sec) master> SET GLOBAL MASTER_VERIFY_CHECKSUM=1; Query OK, 0 ROWS affected (0.00 sec) master> SHOW BINLOG EVENTS FROM 261; ERROR 1220 (HY000): Error WHEN executing command SHOW BINLOG EVENTS: Wrong offset OR I/O error
果真就校验出错了。
按照以下的步骤,可以在从服务器上进行类似的实验:
1 START SLAVE IO_THREAD. 2 一段时间之后 STOP SLAVE. 3 直接编辑relay log 4 START SLAVE。 slave> SHOW SLAVE STATUS\G *************************** 1. ROW *************************** . . . Master_Log_File: master-bin.000001 Read_Master_Log_Pos: 550 Relay_Log_File: slave-relay-bin.000002 Relay_Log_Pos: 419 Relay_Master_Log_File: master-bin.000001 Slave_IO_Running: Yes Slave_SQL_Running: No . . . Last_IO_Errno: 0 Last_IO_Error: Last_SQL_Errno: 1594 Last_SQL_Error: Relay log READ failure: Could NOT parse relay log event entry. The possible reasons are: the master's binary log is corrupted... . . . Last_SQL_Error_Timestamp: 110406 09:41:40 1 row in set (0.00 sec)
看来是相当管用啊。
不过,这也只能发现错误,却不知道是哪条SQL语句出了问题。
MySQL team又推出了新版本的mysqlbinlog。
原来的mysqlbinlog主要作用就是把mysql二进制日志转化为文本形式,现在又加上了校验功能。
$ client/mysqlbinlog --verify-binlog-checksum master-bin.000001 . . . # at 261 #110406 8:35:28 server id 1 end_log_pos 333 CRC32 0xed927ef2 Query thread_id=1... SET TIMESTAMP=1302071728/*!*/; BEGIN /*!*/; # at 333 #110406 8:35:28 server id 1 end_log_pos 365 CRC32 0x01ed254d Intvar SET INSERT_ID=1/*!*/; ERROR: Error IN Log_event::read_log_event(): 'Event crc check failed! Most likely... DELIMITER ; # End of log file ROLLBACK /* added by mysqlbinlog */; /*!50003 SET COMPLETION_TYPE=@OLD_COMPLETION_TYPE*/;
��便提一句,CRC32也打印出来了(32位的)。
