mysql 表数据误删除后怎样恢复
1、构建测试环境数据create table t1(a varchar(10),b varchar(10));insert into t1 values('1','1');insert into t1 values('2','2');commit;
2、模拟误修改,将t1表中的b字段更新为错误数据 "123456"update t1 set b='123456' where a='1';commit;select * from t1;
3、将恢复工具上传到服务器并进行解压。unzip binlog2sql-master.zip
4、得到误修改时的binlog文件(show binary logs;),我的实验环境是mysql-bin.000011。
5、通过binlog2sql.py 脚本的到所有 对表 t1 的修改操作。python binlog2s鳎溻趄酃ql.py -hlocalhost -P23307 -ubinlog2sql -p'binlog2sql' -dtest -tt1 --start-file='mysql-bin.000011'
6、得到了误操作sql的准确位置在1382-1615之间,使用 _**-B**_ 选项生成回滚sql。python bi荏鱿胫协nlog2sql.py -hlocalhost -P23307 -ubinlog2sql -p'binlog2sql' -dtest -tt1 --start-file='mysql-bin.000011' --start-position=1382 --stop-position=1615 -B
7、执行得到的回滚语句进行误操作恢复。
8、binlog2sql 安装步骤,如果没有外网可以手工下载安装包进行安装。git clone https://github.艘早祓胂com/danfengcao/binlog2sql.git && cd binlog2sqlpip install -r requirements.txtGRANT SELECT, REPLICATION SLAVE, REPLICATION CLIENT ON *.* TO 'binlog2sql'@'%' identified by 'binlog2sql';