| C:ProgramDataMySQLMySQL Server 5.1data>mysqlbinlog mysql_bin.000001 /*!40019 SET @@session.max_insert_delayed_threads=0*/; /*!50003 SET @OLD_COMPLETION_TYPE=@@COMPLETION_TYPE,COMPLETION_TYPE=0*/; DELIMITER /*!*/; # at 4 #121015 16:35:56 server id 1 end_log_pos 106 Start: binlog v 4, server v 5.1.51-community-log created 121015 16:35:56 at startup ROLLBACK/*!*/; BINLOG ' 7Mp7UA8BAAAAZgAAAGoAAAAAAAQANS4xLjUxLWNvbW11bml0eS1sb2cAAAAAAAAAAAAAAAAAAAAA AAAAAAAAAAAAAAAAAADsyntQEzgNAAgAEgAEBAQEEgAAUwAEGggAAAAICAgC '/*!*/; # at 106 #121015 16:36:51 server id 1 end_log_pos 174 Query thread_id=2 exec_time=0 error_code=0 SET TIMESTAMP=1350290211/*!*/; SET @@session.pseudo_thread_id=2/*!*/; SET @@session.foreign_key_checks=1, @@session.sql_auto_is_null=1, @@session.unique_checks=1, @@session.autocommit=1/*!*/; SET @@session.sql_mode=1344274432/*!*/; 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 174 #121015 16:36:51 server id 1 end_log_pos 202 Intvar SET INSERT_ID=3/*!*/; # at 202 #121015 16:36:51 server id 1 end_log_pos 309 Query thread_id=2 exec_time=0 error_code=0 use test/*!*/; SET TIMESTAMP=1350290211/*!*/; insert into bin(name) values('xishizhaohua') /*!*/; # at 309 #121015 16:36:51 server id 1 end_log_pos 336 Xid = 28 COMMIT/*!*/; # at 336 #121015 16:37:25 server id 1 end_log_pos 379 Rotate to mysql_bin.000002 pos: 4 DELIMITER ; # End of log file ROLLBACK /* added by mysqlbinlog */; /*!50003 SET COMPLETION_TYPE=@OLD_COMPLETION_TYPE*/; |
虽然排版有点乱,但从图中我们可以得到更多信息,如时间戳,自增的偏移,是否自动提交事务等信息。如下图为从中提取的一部分。

3.利用bin_log恢复数据
(1).最长用的就是回复指定数据端的数据了,可以直接恢复到数据库中:
| mysqlbinlog --start-date="2012-10-15 16:30:00" --stop-date="2012-10-15 17:00:00" mysql_bin.000001 |mysql -uroot -p123456 |
亦可导出为sql文件,再导入至数据库中:
| mysqlbinlog --start-date="2012-10-15 16:30:00" --stop-date="2012-10-15 17:00:00" mysql_bin.000001 >d:1.sql source d:1.sql |
(2).指定开始结束位置,从上面的查看产生的binary log我们可以知道某个log的开始到结束的位置,我们可以在恢复的过程中指定回复从A位置到B位置的log.需要用下面两个参数来指定:










