MyFlash is an open source tool released by Meituan-Dianping which can be used to flashback MySQL DML data.here's the github link:
https://github.com/Meituan-Dianping/MyFlash
after downloaded the tool and extracted the zip package,i got this structure:
<wiz_code_mirror>
[root@zlm1 16:25:26 /vagrant/MyFlash-master]
#ls -l
total 8
drwxrwxrwx 1 vagrant vagrant 0 Jun 1 16:17 binary
-rwxrwxrwx 1 vagrant vagrant 95 Oct 25 2017 build.sh
drwxrwxrwx 1 vagrant vagrant 0 Jun 1 16:17 doc
-rwxrwxrwx 1 vagrant vagrant 1103 Oct 25 2017 License.md
-rwxrwxrwx 1 vagrant vagrant 1273 Oct 25 2017 README.md
drwxrwxrwx 1 vagrant vagrant 0 Jun 1 16:17 source
drwxrwxrwx 1 vagrant vagrant 4096 Jun 1 16:17 testbinlog
the official document recommend to install the tool by dynamic compliling link way to install,but i prefer to use the binary way instead.let's see the parameter and usage of the command:
<wiz_code_mirror>
[root@zlm1 16:27:20 /vagrant/MyFlash-master/binary]
#./flashback --help
Usage:
flashback [OPTION...]
Help Options:
-h, --help Show help options
Application Options:
--databaseNames databaseName to apply. if multiple, seperate by comma(,)
--tableNames tableName to apply. if multiple, seperate by comma(,)
--start-position start position
--stop-position stop position
--start-datetime start time (format %Y-%m-%d %H:%M:%S)
--stop-datetime stop time (format %Y-%m-%d %H:%M:%S)
--sqlTypes sql type to filter . support INSERT, UPDATE ,DELETE. if multiple, seperate by comma(,)
--maxSplitSize max file size after split, the uint is M
--binlogFileNames binlog files to process. if multiple, seperate by comma(,)
--outBinlogFileNameBase output binlog file name base
--logLevel log level, available option is debug,warning,error
--include-gtids gtids to process
--exclude-gtids gtids to skip
<wiz_code_mirror>
root@localhost:mysql3306.sock [zlm]05:35:42>create table test_flashbk(
-> id bigint not null auto_increment,
-> name varchar(20) not null default '',
-> primary key(id)
-> ) engine=innodb default charset=utf8mb4;
Query OK, 0 rows affected (0.04 sec)
root@localhost:mysql3306.sock [zlm]05:35:53>delimiter //
root@localhost:mysql3306.sock [zlm]05:36:10>create procedure pro_flashbk()
-> begin
-> declare id int;
-> set id = 100000;
-> while id>0 do
-> insert into test_flashbk(name) values ('aaron8219');
-> set id=id-1;
-> end while;
-> end //
Query OK, 0 rows affected (0.04 sec)
root@localhost:mysql3306.sock [zlm]05:36:11>delimiter ;
root@localhost:mysql3306.sock [zlm]05:36:23>call pro_flashbk();
Query OK, 1 row affected (11.06 sec)
root@localhost:mysql3306.sock [zlm]05:36:41>select count(*) from test_flashbk;
+----------+
| count(*) |
+----------+
| 100000 |
+----------+
1 row in set (0.02 sec)
root@localhost:mysql3306.sock [zlm]05:37:17>select id,name from test_flashbk limit 0,5;
+----+-----------+
| id | name |
+----+-----------+
| 1 | aaron8219 |
| 2 | aaron8219 |
| 3 | aaron8219 |
| 4 | aaron8219 |
| 5 | aaron8219 |
+----+-----------+
5 rows in set (0.00 sec)
root@localhost:mysql3306.sock [zlm]05:38:04>select @@autocommit;
+--------------+
| @@autocommit |
+--------------+
| 1 |
+--------------+
1 row in set (0.03 sec)
root@localhost:mysql3306.sock [zlm]05:38:12>
<wiz_code_mirror>
root@localhost:mysql3306.sock [zlm]05:38:12>update test_flashbk set name='zlm';
Query OK, 100000 rows affected (2.29 sec)
Rows matched: 100000 Changed: 100000 Warnings: 0
root@localhost:mysql3306.sock [zlm]05:39:00>select id,name from test_flashbk limit 0,5;
+----+------+
| id | name |
+----+------+
| 1 | zlm |
| 2 | zlm |
| 3 | zlm |
| 4 | zlm |
| 5 | zlm |
+----+------+
5 rows in set (0.00 sec)
root@localhost:mysql3306.sock [zlm]05:39:09>show master status;
+------------------+----------+--------------+------------------+------------------------------------------------+
| File | Position | Binlog_Do_DB | Binlog_Ignore_DB | Executed_Gtid_Set |
+------------------+----------+--------------+------------------+------------------------------------------------+
| mysql-bin.000018 | 72724124 | | | 2a4b3562-2ab6-11e8-be7a-080027de0e0e:1-1100032 |
+------------------+----------+--------------+------------------+------------------------------------------------+
1 row in set (0.00 sec)
root@localhost:mysql3306.sock [zlm]05:39:26>exit
Bye
<wiz_code_mirror>
[root@zlm1 17:40:34 ~]
#cd /data/mysql/mysql3306/logs
[root@zlm1 17:40:50 /data/mysql/mysql3306/logs]
#ls -l
total 368408
-rw-r----- 1 mysql mysql 217 May 26 15:37 mysql-bin.000013
-rw-r----- 1 mysql mysql 1341 May 26 22:24 mysql-bin.000014
-rw-r----- 1 mysql mysql 217 May 26 22:24 mysql-bin.000015
-rw-r----- 1 mysql mysql 680 May 30 21:22 mysql-bin.000016
-rw-r----- 1 mysql mysql 268435617 Jun 1 16:57 mysql-bin.000017
-rw-r----- 1 mysql mysql 72724124 Jun 1 17:39 mysql-bin.000018
-rw-r----- 1 mysql mysql 264 Jun 1 16:57 mysql-bin.index
[root@zlm1 17:40:53 /data/mysql/mysql3306/logs]
#
<wiz_code_mirror>
[root@zlm1 17:08:21 ~]
#cd /vagrant/MyFlash-master/binary/
[root@zlm1 17:09:19 /vagrant/MyFlash-master/binary]
#./flashback --databaseNames zlm --tableNames test_flashbk --sqlTypes update --binlogFileNames=/data/mysql/mysql3306/logs/mysql-bin.000018
9.binlogFileNames指定需要回滚的binlog文件,目前只支持单个文件,后续会增加多个文件支持