可以看到当前binlog是:mysql-binlog.000002
位置偏移量:2091
第七步:需要预估下时间,误操作的时间范围应该在下午2点20分到2点30分之间。命令如下:
python binlog2sql.py -h192.168.56.102 -P3306 -uzs_test -p123456 -dzs -tt --start-file='mysql-binlog.000002' --start-datetime='2017-11-30 14:20:00' --stop-datetime='2017-11-30 14:30:00' 输出结果:
DELETE FROM zs.t WHERE address='bj' AND id=1 AND name='aaa' LIMIT 1; #start 1214 end 1427 time 2017-11-30 14:27:46
DELETE FROM zs.t WHERE address='sh' AND id=2 AND name='bbb' LIMIT 1; #start 1214 end 1427 time 2017-11-30 14:27:46
DELETE FROM zs.t WHERE address='gz' AND id=3 AND name='ccc' LIMIT 1; #start 1214 end 1427 time 2017-11-30 14:27:46
DELETE FROM zs.t WHERE address='sy' AND id=4 AND name='ddd' LIMIT 1; #start 1214 end 1427 time 2017-11-30 14:27:46
DELETE FROM zs.t WHERE address='fj' AND id=5 AND name='eee' LIMIT 1; #start 1214 end 1427 time 2017-11-30 14:27:46
从解析结果中我们了解到,误操作sql的位置是在1214~1427之间;这样就可以进一步过滤,使用flashback模式生成回滚sql;
命令如下:
python binlog2sql.py -h192.168.56.102 -P3306 -uzs_test -p123456 -dzs -tt --start-file='mysql-binlog.000002' --start-position=1214 --stop-position=1427 -B >t_rollback.sql 查看闪回导出文件:
[root@node3 binlog2sql]# cat t_rollback.sql
INSERT INTO `zs`.`t`(`address`, `id`, `name`) VALUES ('fj', 5, 'eee'); #start 1214 end 1427 time 2017-11-30 14:27:46
INSERT INTO `zs`.`t`(`address`, `id`, `name`) VALUES ('sy', 4, 'ddd'); #start 1214 end 1427 time 2017-11-30 14:27:46
INSERT INTO `zs`.`t`(`address`, `id`, `name`) VALUES ('gz', 3, 'ccc'); #start 1214 end 1427 time 2017-11-30 14:27:46
INSERT INTO `zs`.`t`(`address`, `id`, `name`) VALUES ('sh', 2, 'bbb'); #start 1214 end 1427 time 2017-11-30 14:27:46
INSERT INTO `zs`.`t`(`address`, `id`, `name`) VALUES ('bj', 1, 'aaa'); #start 1214 end 1427 time 2017-11-30 14:27:46