Mysql数据误删除快速回滚
在数据库操作中,难免会因为各种各样的原因对数据造成损坏,这个时候就需要对数据库快速恢复。传统的方法会先恢复mysql备份,再去用mysqlbinlog抽取指定时间点的日志,再恢复,这样的操作比较耗时,容易出错,那有没有一种工具可以快速把误删除的操作SQL逆过来,然后重新插入误删除的数据呢?
binlog2sql,就是一个很好的应用,它可以从MySQL binlog解析出SQL,根据不同选项,你可以得到原始SQL、回滚SQL、去除主键的INSERT SQL等。
演示环境说明:
- 数据库:Mysql5.6
- 操作系统:Centos7为例
- 演示场景:2018年10月31日10:56,删除整个表的数据,演示快速回滚被删除的数据
操作步骤
1、回滚之前先确认一下Mysql Server配置参数

2、如果你没有mysql命令,那么需要安装对应版本的Mysql客户端,Centos7对应的mysql客户端包是mariadb,Centos6客户端包是mysql

3、安装binlog2sql回滚工具

4、授权用于回滚的Mysql用户

5、开始实验:模拟误删除

6、查看误删除时间点写入的binlog文件

7、查看误删除时间点的操作SQL

8、生成回滚SQL

9、登录mysql,对数据进行回滚

可以看到被删除的两条数据已经恢复。
工具参数说明:

当然数据库恢复是修复操作,是对已经发生问题的进行的补救措施。咱们实际业务中还是应该应该重视流程和测试,避免数据库误操作。数据库毕竟关系到用户的核心利益。