通过 MySQL 二进制日志恢复删除的记录

栏目: 数据库 · 发布时间: 5年前

内容简介:删除 MySQL 表中的数据mysql> use sbtest;mysql> select count(*) from sbtest1;

删除 MySQL 表中的数据

mysql> use sbtest;

mysql> select count(*) from sbtest1;

+----------+

| count(*) |

+----------+

|    1000 |

+----------+

1 row in set (0.00 sec)

mysql> delete from sbtest1;

Query OK, 1000 rows affected (0.21 sec)

mysql> select count(*) from sbtest1;

+----------+

| count(*) |

+----------+

|        0 |

+----------+

1 row in set (0.00 sec)

确认时间点和当前二进制日志文件,从二进制日志中读取操作记录

mysqlbinlog \

--start-datetime="2018-09-27 15:55:00" \

--stop-datetime="2018-09-27 15:00:00" \

--base64-output=decode-rows \

--result-file=result.sql \

-v /var/lib/mysql/binlog.000022

其中的一条记录

通过 MySQL 二进制日志恢复删除的记录

去除不相关的内容

grep -A 5 "DELETE FROM \`sbtest\`.\`sbtest1\`" result.sql > 1.txt

通过 MySQL 二进制日志恢复删除的记录

提取数据

grep "=" 1.txt > 2.txt

sed -i 's/###  //g' 2.txt

通过 MySQL 二进制日志恢复删除的记录

使用以下脚本生成 INSERT 语句

[root@mysql03 tmp]# cat r2.sh

#!/bin/bash

vs=""

while read line

do

n=`echo $line | awk -NF "=" '{print $1}'`

v=`echo $line | awk -NF "=" '{print $2}'`

if [ "$n" = "@1" ]; then

vs="INSERT INTO \`sbtest\`.\`sbtest1\` VALUES("$v

elif [ "$n" = "@2" ]; then

vs=$vs" , "$v

elif [ "$n" = "@3" ]; then

vs=$vs" , "$v

elif [ "$n" = "@4" ]; then

vs=$vs" , "$v");"

echo $vs >> 3.txt

fi

done < 2.txt

[root@mysql03 tmp]# sh r2.sh

通过 MySQL 二进制日志恢复删除的记录

将数据导入到 MySQL 表中

[root@mysql03 tmp]# mysql < 3.txt

mysql> select count(*) from sbtest1;

+----------+

| count(*) |

+----------+

|    1000 |

+----------+

1 row in set (0.00 sec)


以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持 码农网

查看所有标签

猜你喜欢:

本站部分资源来源于网络,本站转载出于传递更多信息之目的,版权归原作者或者来源机构所有,如转载稿涉及版权问题,请联系我们

Computing Patterns in Strings

Computing Patterns in Strings

Bill Smyth / Addison Wesley / 2003 / $ 75.00

The computation of patterns in strings is a fundamental requirement in many areas of science and information processing. The operation of a text editor, the lexical analysis of a computer program, the......一起来看看 《Computing Patterns in Strings》 这本书的介绍吧!

CSS 压缩/解压工具
CSS 压缩/解压工具

在线压缩/解压 CSS 代码

在线进制转换器
在线进制转换器

各进制数互转换器

SHA 加密
SHA 加密

SHA 加密工具