Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

[MySQL] Database flashback tool-- binlog2sql

2025-01-17 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Database >

Share

Shulou(Shulou.com)06/01 Report--

[root@wallet01] # cat / etc/redhat-release CentOS Linux release 7.5.1804 (Core) [root@wallet01] # python- VPython 2.7.5 [root@wallet01] # yum install-y python-pip [root@wallet01] # pip-Vpip 8.1.2 from / usr/lib/python2.7/site-packages (python2.7) [root@wallet01] # git clone https://github.com/danfengcao/binlog2sql.gitInitialized empty Git repository in / root/binlog2sql/.git/remote: Enumerating objects: 323 Done.remote: Total 323 (delta 0), reused 0 (delta 0), pack-reused 323Receiving objects: 100% (323 KiB/s 323), 151.51 KiB | 245 KiB/s, done.Resolving deltas: 100% (170 KiB/s) Done. [root@wallet01 ~] # cd binlog2sql [root@wallet01 binlog2sql] # pip install-r requirements.txt [root@wallet01 binlog2sql] # cd binlog2sql/ [root@wallet01 binlog2sql] # python binlog2sql.py-- helpusage: binlog2sql.py [- h HOST] [- u USER] [- p [PASSWORD [PASSWORD...] [- P PORT] [--start-file START_FILE] [--start -position START_POS] [--stop-file END_FILE] [--stop-position END_POS] [--start-datetime START_TIME] [--stop-datetime STOP_TIME] [--stop-never] [--help] [- d [DATABASES [DATABASES.] [ -t [TABLES [TABLES...]] [--only-dml] [--sql-type [SQL_TYPE [SQL_TYPE...] [- K] [- B] [--back-interval BACK_INTERVAL]-- start-file-- start parsing file-- stop-file-- terminating parsing file -- start-position-- start resolution position-- stop-position-- end resolution location-- start-datetime-- start resolution time Format'% Y-%m-%d% HRV% MRV% S'. -- stop-datetime-- the resolution time is terminated in the format'% Y-%m-%d% HRV% MRO% S'. -d-- resolves only the sql-t of the target db-- resolves only the sql--only-dml of the target table-- parses only dml and ignores ddl. -- sql-type-- only the specified type is parsed, and insert,update,delete is supported. -B-- generate rollback SQL [root@wallet01 ~] # mysql-uroot-pEnter password: mysql > grant select,replication client,replication slave on *. * to 'fb'@'%' identified by' fb@2019'; Query OK, 0 rows affected (0. 05 sec) mysql > flush privileges;Query OK, 0 rows affected (0. 11 sec) mysql > show master status +-+ | File | Position | Binlog_Do_DB | Binlog_Ignore_DB | Executed_Gtid_Set | +- -+ | mysql-bin.000008 | 120 | +- -+ 1 row in set (0.00 sec) mysql > select now () +-+ | now () | +-+ | 0-10-12 17:18:22 | +-+ 1 row in set (0.06 sec) mysql > use gsoamysql > select count (*) from bd_city +-+ | count (*) | +-+ | 372 | +-+ 1 row in set (0.00 sec) mysql > begin;Query OK, 0 rows affected (0.00 sec) mysql > delete from bd_city;Query OK, 372 rows affected (0.09 sec) mysql > commit;Query OK, 0 rows affected (0.04 sec) mysql > select count (*) from bd_city +-+ | count (*) | +-+ | 0 | +-+ 1 row in set (0.01sec) mysql > select now () +-+ | now () | +-+ | 0-10-12 17:22:26 | +-+ 1 row in set (sec) restore deleted records in committed transactions [root@wallet01 binlog2sql] # python binlog2sql .py-hlocalhost-P3306-ufb-pallefbaked 2019'- dgsoa-tbd_city\-- start-file='mysql-bin.000008'-- only-dml-- sql-type=delete\-- start-datetime='2019-10-12 17dgsoa 1822 more fb.log DELETE FROM 22'--stop-datetime='2019-10-12 17dgsoa 22'> fb.log [root@wallet01 binlog2sql] # more fb.log DELETE FROM `gsoa`.`bd _ city`status` ='1' AND `parent_ name` = 'China' AND `code` = '110000 'AND `name` =' Beijing 'AND `parent_ code` =' CN' LIMIT 1 # start 423 end 8756 time 2019-10-12 17:21:26 [root@wallet01 binlog2sql] # tail-n 1 fb.log DELETE FROM `gsoa`.`bd _ city`WHERE `status` ='1' AND `parent_ name` =''AND `code` =' CN' AND `name` = 'China' AND `parent_ code` =''LIMIT 1 # start 423 end 19319 time 2019-10-12 17:21:26 [root@wallet01 binlog2sql] # python binlog2sql.py-hlocalhost-P3306-ufb-pallefbaked 2019'-dgsoa-tbd_city\-start-file='mysql-bin.000008'-- start-position=423-- stop-position=19319-B > rollback.sql [root@wallet01 binlog2sql] # more rollback.sql | grep 'Beijing' INSERT INTO `gsoa`.`bd _ city` (`status`, `parent_ name`, `code`, `name`, `parent_ code`) VALUES ('1century,' China') '110000yuan,' Beijing', 'CN') # start 423 end 8756 time 2019-10-12 17:21:26 [root@wallet01 binlog2sql] # mysql-uroot-p

< rollback.sql Enter password: [root@wallet01 ~]# mysql -uroot -pEnter password: mysql>

Use gsoamysql > select count (*) from bd_city;+-+ | count (*) | +-+ | 372 | +-+ 1 row in set (0.00 sec)

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Database

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report