SZD-L0087668:gzz3306:Master > python2.7 mysql_rollback.py -f mysql-bin.000009 -o rollback.sql -h127.0.0.1 -P3306 -uroot -p123456 --start-position='2426' --stop-position='2604' -d db1
正在获取参数.....
正在解析binlog.....
正在初始化列名.....
正在开始拼凑sql.....
done!
查看rollback.sql中误操作的逆向语句
SZD-L0087668:gzz3306:Master > cat rollback.sql
## at 2482
##180503 14:13:36 server id 1 end_log_pos 2573 CRC32 0xacd94a0b Update_rows: table id 76 flags: STMT_END_F
UPDATE `db1`.`test`
SET
id=2
,name='bob'
,age=25
,country='britain'
,city='london'
WHERE
id=2
AND
AND age=25
AND country='europe'
AND city='london';
step4.回滚
SZD-L0087668:gzz3306:Master > mysql -uroot -p <rollback.sql
Enter password:
SZD-L0087668:gzz3306:Master > mysql -uroot -p -e 'select * from db1.test';
Enter password:
+------+-------+------+---------+----------+
| id | name | age | country | city |
+------+-------+------+---------+----------+
| 1 | alex | 26 | china | shanghai |
| 2 | bob | 25 | britain | london |
| 3 | simon | 24 | france | paris |
+------+-------+------+---------+----------+
test表已回滚。
mysql_rollback.py脚本可以到Linux公社资源站下载:
------------------------------------------分割线------------------------------------------
具体下载目录在 /2018年资料/5月/3日/使用Python脚本实现MySQL误操作的快速回滚/
------------------------------------------分割线------------------------------------------