### DELETE FROM `test`.`test` ### WHERE ### @1=1 ### @2='name1' ### @3='memo1' ### DELETE FROM `test`.`test` ### WHERE ### @1=3 ### @2='name3' ### @3='memo3' # at 998969666update操作对应binlog日志中的SQL
### UPDATE `test`.`test` ### WHERE ### @1=2 ### @2='name2' ### @3='memo2' ### SET ### @1=2 ### @2='name2' ### @3='new' ### UPDATE `test`.`test` ### WHERE ### @1=4 ### @2='name4' ### @3='memo4' ### SET ### @1=4 ### @2='name4' ### @3='new' # at 998971422
insert操作对应binlog日志中的SQL
### INSERT INTO `test`.`test` ### SET ### @1=6 ### @2='name6' ### @3='memo6' # at 998973859值得一提的是-v(--verbose)选项会将行事件重构成被注释掉的伪SQL语句,如果想看到更详细的信息可以使用-vv选项,这样可以包含一些数据类型和元信息的注释内容。
比如:
-vv的结果:
### DELETE FROM `test`.`test` ### WHERE ### @1=1 /* INT meta=0 nullable=0 is_null=0 */ ### @2='name1' /* VARSTRING(60) meta=60 nullable=1 is_null=0 */ ### @3='memo1' /* VARSTRING(150) meta=150 nullable=1 is_null=0 */回到数据恢复的问题,如果需要手工恢复就需要做几件事情,一个就是根据字段标示拼接出可运行的SQL语句,然后按照逆向的顺序执行即可。
# python setup.py install Traceback (most recent call last): File "setup.py", line 6, in <module> from setuptools import setup, find_packages ImportError: No module named setuptools看来还和一个setuptools的库有关,我们继续安装。
GRANT SELECT, REPLICATION SLAVE, REPLICATION CLIENT ON *.* TO 'admin'@'127.0.0.1' IDENTIFIED BY 'admin';比如我们使用如下的命令来解析binlog得到指定时间戳范围内的SQL情况,在此我们限定数据为test
#cat /tmp/tmp.log DELETE FROM `test`.`test` WHERE `memo`='memo1' AND `id`=1 AND `name`='name1' LIMIT 1; #start 11127 end 11321 time 2017-02-06 04:15:23 DELETE FROM `test`.`test` WHERE `memo`='memo3' AND `id`=3 AND `name`='name3' LIMIT 1; #start 11127 end 11321 time 2017-02-06 04:15:23 UPDATE `test`.`test` SET `memo`='new', `id`=2, `name`='name2' WHERE `memo`='memo2' AND `id`=2 AND `name`='name2' LIMIT 1; #start 11400 end 11625 time 2017-02-06 04:15:29 UPDATE `test`.`test` SET `memo`='new', `id`=4, `name`='name4' WHERE `memo`='memo4' AND `id`=4 AND `name`='name4' LIMIT 1; #start 11400 end 11625 time 2017-02-06 04:15:29 INSERT INTO `test`.`test`(`memo`, `id`, `name`) VALUES ('memo6', 6, 'name6'); #start 12062 end 12239 time 2017-02-06 04:15:37其实看起来还是很省事了。
#cat /tmp/tmp.log DELETE FROM `test`.`test` WHERE `memo`='memo6' AND `id`=6 AND `name`='name6' LIMIT 1; #start 12062 end 12239 time 2017-02-06 04:15:37 UPDATE `test`.`test` SET `memo`='memo4', `id`=4, `name`='name4' WHERE `memo`='new' AND `id`=4 AND `name`='name4' LIMIT 1; #start 11400 end 11625 time 2017-02-06 04:15:29 UPDATE `test`.`test` SET `memo`='memo2', `id`=2, `name`='name2' WHERE `memo`='new' AND `id`=2 AND `name`='name2' LIMIT 1; #start 11400 end 11625 time 2017-02-06 04:15:29 INSERT INTO `test`.`test`(`memo`, `id`, `name`) VALUES ('memo3', 3, 'name3'); #start 11127 end 11321 time 2017-02-06 04:15:23 INSERT INTO `test`.`test`(`memo`, `id`, `name`) VALUES ('memo1', 1, 'name1'); #start 11127 end 11321 time 2017-02-06 04:15:23运行了如上的语句之后,再次查看数据,数据就恢复了正常。