当前位置:网站首页>Solution to rollback of MySQL database by mistake deletion
Solution to rollback of MySQL database by mistake deletion
2022-06-30 19:56:00 【1024 Q】
One careless time , It was used delete from xxx Deleted several important data , I found a lot of ways on the Internet , But they are scattered , We intend to record the process of data retrieval .
It is roughly divided into the following steps
1、 see binlog Open or not
# log_bin yes ON, It means that it is opened OFF It's off , The following operations , Only for ON Effective when .show variables like 'log_bin';2、 find binlog file name
show master logs;Run the above code , Here's the picture TS1-bin.000009 Is the file name we are looking for

3、 see binlog Log location
show variables like '%datadir%';4、 According to the position obtained above , Go find TS1-bin.000009 file
5、 Enter into mysql Installation directory bin Under the table of contents , Execute the following command to start from... According to the time range of accidental deletion TS1-bin.000009 File export to sql file
mysqlbinlog --base64-output=decode-rows -v --database= Database name --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 Here I put TS1-bin.000009 The file is copied to the desktop , Because there are spaces in the original storage path of the file , Causes command execution to fail , Can't find the path .
obtain mysqllog.sql After the document , You can open it in Notepad , Search for DELETE keyword , Find the record to delete data
6、 take DELETE The sentence is transformed into INSERT sentence , stay windows Next use vbs To achieve , Copy and save the following code as :deleteToinsert.vbs file ( Must be .vbs Format file ) And mysqllog.sql In the same directory , And then double click , Will generate mysqllogOK.sql The document is what we want INSERT sentence
'========================== ' use VBS Realization MYSQL binglog DELETE turn 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 turn INSERT================'VBS open the text file Set oldStream = CreateObject("ADODB.Stream")oldStream.CharSet = "utf-8"oldStream.OpenoldStream.LoadFromFile("mysqllog.sql") 'binLog Generated DELETE Original log file 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 Save the file 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 Turn into INSERT Later new SQL file name newStream.Close7、 Get the corresponding INSERT Execute after statement .
Reference articlehttps://blog.csdn.net/qq_36602951/article/details/120729047
https://juejin.cn/post/7028955574242902023
This is about MySQL This is the end of the article on how to solve the problem of database accidental deletion rollback , More about MySQL Please search the previous articles of SDN or continue to browse the following related articles. I hope you will support SDN more in the future !
边栏推荐
- Buttons to achieve various effects and functions. Reading this article is enough
- 为什么一定要从DevOps走向BizDevOps?
- GeoServer安装
- 将 EMQX Cloud 数据通过公网桥接到 AWS IoT
- Await and async
- composer
- Lombok
- 漫画 | Oracle 被新时代抛弃了吗?
- 英语没学好到底能不能做coder,别再纠结了先学起来
- 【论文阅读】Trajectory-guided Control Prediction for End-to-end Autonomous Driving: A Simple yet Strong Baseline
猜你喜欢

“更福特、更中国”拨云见日,长安福特王牌产品订单过万

软件工程最佳实践——项目需求分析

Idle fish is hard to turn over

Force deduction ----- count the string containing the given prefix

腾讯会议应用市场正式上线,首批入驻超20款应用

说实话ThreadLocal真不是啥高级的东西

测试必备工具 —— Postman实战教程

MySQL billing Statistics (Part 1): MySQL installation and client dbeaver connection

Primary school, session 3 - afternoon: Web_ xxe

VoIP Push 在海外音视频业务中的应用
随机推荐
WeakSet
Code shoe set - mt3111 · assignment
WordPress 博客使用火山引擎 veImageX 进行静态资源 CDN 加速(免费)
History, selection strategy and in-depth evaluation of note taking software
MySQL数据库误删回滚的解决
DNS服务器搭建、转发、主从配置
软件工程最佳实践——项目需求分析
yolo 目标检测
neo4j load csv 配置和使用
MQ selection (2022.5.9-5.15)
discuz 论坛提速之删除data/log下的xxx.php文件
S7-1500 PLC之间进行TCP通信的具体方法和步骤详解(图文)
8 - 函数
DELL R720服务器安装网卡Broadcom 5720驱动
小学期,第三场-下午:WEB_sessionlfi
Primary school, session 3 - afternoon: Web_ xxe
Final chapter of binary tree
c语言数组截取,C# 字符串按数组截取方法(C/S)
如何做好测试用例设计
网易云签到可抽奖?那一年我能签到365天。不信?你看。