?????????????????????????????????????????????£??????????????MySQL?????????ο??????????磬delete???????????????????????????????????????????????????????????????????????????????????????????????
?????????
???????????????????????????????binlog?????????????????????????????????????SQL??????????binlog??????????????????????????
????????binlog2sql????????
???????????????MySQL server??????binlog???????????2???:
????[mysqld]
????server-id = 1
????log_bin = /var/log/mysql/mysql-bin.log
????max_binlog_size = 1000M
????binlog-format = row
?????????п???binlog???????????????SQL??????????????????????????????????????MySQL??????????binlog??
?????????????????binlog2sql??binlog2sql???????????binlog??????????????????????????binlog?????????
????git clone https://github.com/danfengcao/binlog2sql.git
????pip install -r requirements.txt
????????????????????SQL???
???????????????test??tbl????????????????????????
????test??tbl?????????
????mysql> select * from tbl;
????+----+--------+---------------------+
????| id | name   | addtime             |
????+----+--------+---------------------+
????|  1 | С??   | 2016-12-10 00:04:33 |
????|  2 | С?   | 2016-12-10 00:04:48 |
????|  3 | С??   | 2016-12-10 00:04:51 |
????|  4 | С??   | 2016-12-10 00:04:56 |
????+----+--------+---------------------+
????4 rows in set (0.00 sec)
????mysql> delete from tbl;
????Query OK?? 4 rows affected (0.00 sec)
????tbl??????
????mysql> select * from tbl;
????Empty set (0.00 sec)
?????????????裺
????1?????mysql????????binlog???
????mysql> show master logs;
????+------------------+-----------+
????| Log_name         | File_size |
????+------------------+-----------+
????| mysql-bin.000046 |  12262268 |
????| mysql-bin.000047 |      3583 |
????+------------------+-----------+
????2???μ?binlog?????mysql-bin.000047?????????λ?????SQL??binlogλ??
????MySQL
????$ python binlog2sql/binlog2sql.py -h127.0.0.1 -P3306 -uadmin -p'admin' -dtest -ttbl --start-file='mysql-bin.000047'
?????????
????$ python binlog2sql/binlog2sql.py -h127.0.0.1 -P3306 -uadmin -p'admin' -dtest -ttbl --start-file='mysql-bin.000047'
?????????
????DELETE FROM `test`.`tbl` WHERE `addtime`='2016-12-10 00:04:33' AND `id`=1 AND `name`='С??' LIMIT 1; #start 3346 end 3556
????DELETE FROM `test`.`tbl` WHERE `addtime`='2016-12-10 00:04:48' AND `id`=2 AND `name`='С?' LIMIT 1; #start 3346 end 3556
????DELETE FROM `test`.`tbl` WHERE `addtime`='2016-12-10 00:04:51' AND `id`=3 AND `name`='С??' LIMIT 1; #start 3346 end 3556
????DELETE FROM `test`.`tbl` WHERE `addtime`='2016-12-10 00:04:56' AND `id`=4 AND `name`='С??' LIMIT 1; #start 3346 end 3556