原理介绍请看美团官方博客:
安装:
环境要求:
1、binlog格式必须为row,且binlog_row_image=full
2、仅支持5.6与5.7
3、只能回滚DML(增、删、改)
4.下载地址:https://github.com/Meituan-Dianping/MyFlash
安装:
unzip MyFlash-master.zip
mv MyFlash-master /usr/local/MyFlash/
gcc -w `pkg-config --cflags --libs glib-2.0` source/binlogParseGlib.c -o binary/flashback
闪回:
update,情景描述,程序1误将xtr库下面的t2表12,11更改后0了,这是一个错误的操作;而后面的程序2将13、14更改0了,这是一个正确的操作,需要闪回程序1的误操作。
模似上述场景:
原表:
mysql> select * from xtr.t2;
+------+
| id |
+------+
| 12 |
| 11 |
| 4 |
| 3 |
| 13 |
| 14 |
+------+
6 rows in set (0.00 sec)
update操作:
update xtr.t2 set id = 0 where id = 12;
update xtr.t2 set id = 0 where id = 11;
update xtr.t2 set id = 0 where id = 13;
update xtr.t2 set id = 0 where id = 14;
DBA接到开发的报警后:
1、flush logs;
需要闪回的动作所在的二进制文件,这个文件必须是稳定的,需要flush logs;
2、记录当前的binlog文件
3、解析binlog
mysqlbinlog -vv bin.000038|less
# at 838
#180326 21:41:59 server id 11 end_log_pos 882 CRC32 0x304d887b Table_map: `xtr`.`t2` mapped to number 268 #这个position开始进入xtr.t2库
# at 882
#180326 21:41:59 server id 11 end_log_pos 928 CRC32 0x8fac8e57 Update_rows: table id 268 flags: STMT_END_F
BINLOG '
twa5WhMLAAAALAAAAHIDAAAAAAwBAAAAAAEAA3h0cgACdDIAAQMAAXuITTA=
twa5Wh8LAAAALgAAAKADAAAAAAwBAAAAAAEAAgAB///+CwAAAP4AAAAAV46sjw==
'/*!*/;
### UPDATE `xtr`.`t2` #更改的第一条语句
### WHERE
### @1=11 /* INT meta=0 nullable&