当前位置:网站首页> MySQL数据库误删回滚的解决
MySQL数据库误删回滚的解决
2022-06-30 19:18:00 【1024问】
某次一不小心,用了delete from xxx 删除了几条重要数据,在网上找了很多方法,但都比较零散,打算记录本次数据找回的过程。
大致分为以下几步
1、查看binlog是否开启
# log_bin是ON,就说明打开了 OFF就是关闭状态,以下操作,只有为 ON 时有效。show variables like 'log_bin';2、找到binlog文件名
show master logs;运行以上代码,如下图 TS1-bin.000009 就是我们要找的文件名

3、查看binlog日志位置
show variables like '%datadir%';4、根据上面得到的位置,去找到 TS1-bin.000009 文件
5、进入到mysql安装目录的bin目录下,执行以下命令根据误删除的时间范围从TS1-bin.000009文件导出成sql文件
mysqlbinlog --base64-output=decode-rows -v --database=数据库名 --start-datetime="2022-06-29 15:35:00" --stop-datetime="2022-06-29 15:45:00" C:/Users/Administrator/Desktop/TS1-bin.000009 > C:/Users/Administrator/Desktop/mysqllog.sql这里我把 TS1-bin.000009 文件拷贝到了桌面,因为该文件原始存放路径有空格,导致命令执行失败,无法找到路径。
得到 mysqllog.sql 文件后,可以用记事本打开,搜索 DELETE 关键字,找到删除数据的记录
6、将 DELETE 语句改造成 INSERT 语句,在windows下用vbs来实现,把下面代码复制保存为:deleteToinsert.vbs 文件(一定要是.vbs格式文件) 与mysqllog.sql在同一目录下,然后双击运行,会生成mysqllogOK.sql文件就是我们要的INSERT语句
'========================== '用VBS实现 MYSQL binglog DELETE转INSERT '========================== function replaceregex(patern,str,tagstr) dim regex,matches set regex=new regExp regex.pattern=patern regex.IgnoreCase=true regex.global=true matches=regex.replace(str,tagstr) replaceregex=matches end function'======Mysql binlog DELETE转INSERT================'VBS打开文本文件Set oldStream = CreateObject("ADODB.Stream")oldStream.CharSet = "utf-8"oldStream.OpenoldStream.LoadFromFile("mysqllog.sql") 'binLog生成的DELETE原日志文件oldText = oldStream.ReadText() newText=replace(oldText,"### DELETE FROM", ";INSERT INTO") newText=replace(newText,"### WHERE", "SELECT") newText=replace(newText,"###", "") newText=replace(newText,"@1=", "") newText=replaceregex("\@[1-9]=",newText, ",") newText=replaceregex("\@[1-9][0-9]=",newText, ",")oldStream.Close'VBS保存文件Set newStream = CreateObject("ADODB.Stream")newStream.Type = 2 'Specify stream type - we want To save text/string data.newStream.Charset = "utf-8" 'Specify charset For the source text data.newStream.Open 'Open the stream And write binary data To the objectnewStream.WriteText newTextnewStream.SaveToFile "mysqllogOK.sql", 2 'DELETE转成INSERT以后的新的SQL文件名newStream.Close7、拿到对应的 INSERT 语句后执行。
参考文章https://blog.csdn.net/qq_36602951/article/details/120729047
https://juejin.cn/post/7028955574242902023
到此这篇关于MySQL数据库误删回滚的解决的文章就介绍到这了,更多相关MySQL数据库误删回滚内容请搜索软件开发网以前的文章或继续浏览下面的相关文章希望大家以后多多支持软件开发网!
边栏推荐
- VoIP Push 在海外音视频业务中的应用
- 笔记软件的历史、选择策略以及深度评测
- Graduates
- 今早,投资人开始集体出差
- Growth summer challenge is coming, exclusive community welfare is coming ~ get CSDN customized T-shirt for free
- DNS服务器搭建、转发、主从配置
- 2022年高考都结束了,还有人真觉得程序员下班后不需要学习吗?
- Warmup预热学习率「建议收藏」
- The former king of fruit juice sold for 1.6 billion yuan
- Redis入门到精通01
猜你喜欢

4.3-inch touch screen 12 channel control port programmable network central control supports mutual backup of 5 central control hosts

VoIP Push 在海外音视频业务中的应用

Tupu software has passed CMMI5 certification| High authority and high-level certification in the international software field

项目配置了eslint,编辑器没有关闭eslint功能的情况下,eslint没有生效

S7-1500 PLC之间进行TCP通信的具体方法和步骤详解(图文)

A necessary tool for testing -- postman practical tutorial

Friends in Guangzhou can join us if they have the opportunity

6-1漏洞利用-FTP漏洞利用

昔日果汁大王,16个亿卖了

实现各种效果和功能的按钮,读这篇文章就够了
随机推荐
哪个券商佣金的佣金最低?另外,手机开户安全么?
内存数据库如何发挥内存优势?
Kubevela 1.4: make application delivery safer, easier to use, and more transparent
Convert seconds to * * hours * * minutes
S7-1500 PLC之间进行TCP通信的具体方法和步骤详解(图文)
pycharm从安装到全副武装,学起来才嗖嗖的快,图片超多,因为过度详细!
二叉树终章
Task01: getting to know database and SQL (Note 1)
暑期实训21组第一周个人工作总结
VR全景添加对比功能,让差异化效果展示更直观!
matlab 将三角剖分结果保存为STL文件
The prospectus of pelt medical was "invalid" for the second time in the Hong Kong stock exchange, and the listing plan was substantially delayed
Go language learning tutorial (10)
将秒数转换为**小时**分钟
RP原型资源分享-购物类App
PS2手柄-1「建议收藏」
Friends in Guangzhou can join us if they have the opportunity
成长一夏 挑战赛来袭 专属社区福利来袭~免费获得CSDN定制T恤衫
mysql统计账单信息(上):mysql安装及客户端DBeaver连接使用
Tupu software has passed CMMI5 certification| High authority and high-level certification in the international software field