简单使用binlog2sql实现mysql操作回滚
git clone https://github.com/danfengcao/binlog2sql.git && cd binlog2sql
进入binlog2文件夹编译
pip install -r requirements.txt(若py版本报错,则按照提示运行命令,然后再次运行编译命令)
配置mysql.ini , 将日志记录类型从 mixed 设为 row,重启mysql
[mysqld]
server_id = 1
binlog_format = row
设置 要记录日志的mysql 用户权限,比如

GRANT SELECT, REPLICATION SLAVE, REPLICATION CLIENT ON *.* TO  childrenapi_jayc@'localhost'
查看权限是否赋予
show grants for childrenapi_jayc@'localhost';
查看最近执行记录到binlog的文件

进入binlogsql2目录下

执行
binlog2sql]# python2 binlog2sql/binlog2sql.py -h 127.0.0.1 -P 3306 -u root -p'12c96fd02c617462' -d childrenapi_jayc -t user_children --start-file='mysql-bin.000078' 
其中 'mysql-bin.000078' 为 记录sql语句 的文件

运行命令,会发现最近操作的sql语句

如果要把sql语句存入到一个文件,则可以在尾部加 > test.sql | cat
在此命令尾部加 -B 则可以获取回滚的sql语句
筛选功能,-start-file放在在最后面
如果要筛选时间:
 --start-datetime '2021-11-29 15:49:25' --stop-datetime '2021-11-29 15:49:26' --start-file='mysql-bin.000078'如果要筛选节点:
--start-pos 6422 --stop-pos 52200 --start-file='mysql-bin.000078'开始位置需要和搜素结果匹配
 
                    
                
 
 
                
            
         浙公网安备 33010602011771号
浙公网安备 33010602011771号