安装
[root@test3 MyFlash-master]# cd /opt/mysql/MyFlash-master
[root@test3 MyFlash-master]# gcc -w `pkg-config --cflags --libs glib-2.0` source/binlogParseGlib.c -o binary/flashback
测试
创建测试表(5.7主从架构。主上创建)
mysql> use test;
Reading table information for completion of table and column names
You can turn off this feature to get a quicker startup with -A
Database changed
mysql> CREATE TABLE `testFlashback2` (
-> `id` int(11) NOT NULL AUTO_INCREMENT,
-> `nameShort` varchar(20) DEFAULT NULL,
-> `nameLong` varchar(260) DEFAULT NULL,
-> `amount` decimal(19,9) DEFAULT NULL,
-> `amountFloat` float DEFAULT NULL,
-> `amountDouble` double DEFAULT NULL,
-> `createDatetime6` datetime(6) DEFAULT NULL,
-> `createDatetime` datetime DEFAULT NULL,
-> `createTimestamp` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
-> `nameText` text,
-> `nameBlob` blob,
-> `nameMedium` mediumtext,
-> PRIMARY KEY (`id`)
-> ) ENGINE=InnoDB;
Query OK, 0 rows affected (0.11 sec)
插入回滚测试
mysql> insert into testFlashback2(nameShort,nameLong,amount,amountFloat,amountDouble,createDatetime6,createDatetime,createTimestamp,nameText,nameBlob,nameMedium) values('aaa','bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb',10.5,10.6,10.7,'2017-10-26 10:00:00','2017-10-26 10:00:00','2017-10-26 10:00:00','cccc','dddd','eee');
Query OK, 1 row affected (0.00 sec)
mysql> insert into testFlashback2(nameShort,nameLong,amount,amountFloat,amountDouble,createDatetime6,createDatetime,createTimestamp,nameText,nameBlob,nameMedium) values('aaa','bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb',10.5,10.6,10.7,'2017-10-26 10:00:00','2017-10-26 10:00:00','2017-10-26 10:00:00','cccc','dddd','eee');
Query OK, 1 row affected (0.00 sec)
确认回滚pos
mysql> show master status;
+------------------+----------+--------------+------------------+----------------------------------------------------------------------------------------+
| File | Position | Binlog_Do_DB | Binlog_Ignore_DB | Executed_Gtid_Set |
+------------------+----------+--------------+------------------+----------------------------------------------------------------------------------------+
| mysql-bin.000098 | 2631 | | | 65143c8f-b243-11e8-9428-000c296f1213:1-1076,
ac5c0c9e-a938-11e8-bd29-000c29343240:1-22 |
+------------------+----------+--------------+------------------+----------------------------------------------------------------------------------------+
1 row in set (0.00 sec)
mysql> flush binary logs;
Query OK, 0 rows affected (0.00 sec)
生成回滚的二进制文件
[root@test3 MyFlash-master]# ./binary/flashback --binlogFileNames=/dbdata/mysql/my57_3307/log/binlog/mysql-bin.000098 --start-position=1640 --stop-position=2631 --outBinlogFileNameBase=test_insert_to_delete.flashback
应用到主库
[root@test3 MyFlash-master]# /usr/local/mysql57/bin/mysqlbinlog --skip-gtids test_insert_to_delete.flashback.flashback | /usr/local/mysql57/bin/mysql -uroot -poracle -S /var/run/mysqld/my57_3307.sock
mysql: [Warning] Using a password on the command line interface can be insecure.
从库上检查数据
mysql> select count(*) from testFlashback2;
+----------+
| count(*) |
+----------+
| 0 |
+----------+
1 row in set (0.00 sec)