亚洲乱码中文字幕综合,中国熟女仑乱hd,亚洲精品乱拍国产一区二区三区,一本大道卡一卡二卡三乱码全集资源,又粗又黄又硬又爽的免费视频

MySQL恢復(fù)誤刪數(shù)據(jù)圖文教程

 更新時(shí)間:2023年06月20日 08:43:06   作者:不懂一休  
MySQL誤刪數(shù)據(jù)庫(kù)造成了數(shù)據(jù)的丟失,這是非常尷尬的,下面這篇文章主要給大家介紹了關(guān)于MySQL恢復(fù)誤刪數(shù)據(jù)的相關(guān)資料,文中通過(guò)實(shí)例代碼介紹的非常詳細(xì),需要的朋友可以參考下

MySQL 恢復(fù)誤刪數(shù)據(jù),針對(duì) window 和 Linux 均適用,只需要找到對(duì)應(yīng)的 binlog 目錄文件,默認(rèn)就是 MySQL 安裝目錄下的 data 文件夾

一般誤刪數(shù)據(jù),先停止所有操作,備份數(shù)據(jù)庫(kù)

# 備份所有數(shù)據(jù)庫(kù)
mysqldump -uroot -p123456 --all-databases > /backup/mysqldump/all.db
# 恢復(fù)數(shù)據(jù)
mysql -uroot -p db_name < /backup/mysqldump/db_name.db

1、查看是否啟用 binlog 日志

SHOW VARIABLES LIKE '%log_bin%'

2、查看所有 binlog 日志

SHOW BINARY LOGS;

3、查看正在使用的日志

SHOW MASTER STATUS;

4、查找日志所在文件夾

SHOW VARIABLES LIKE '%datadir%';

5、log 日志轉(zhuǎn) sql

使用上面使用的 binlog.000056 文件,先把 該文件復(fù)制到其他地方

mysqlbinlog E:\test\result\binlog.000056 > E:\test\result\db.sql

有可能報(bào)錯(cuò)

添加 --no-defaults 參數(shù)可以解決,但中文會(huì)亂碼(使用下面 vbs 或自定義語(yǔ)言實(shí)現(xiàn)可解決 亂碼問(wèn)題),一般要加上時(shí)間字段轉(zhuǎn)換 sql

mysqlbinlog --no-defaults --base64-output=decode-rows -v --database=oauth --start-datetime="2023-06-01 01:44:00" --stop-datetime="2023-06-01 01:48:00" F:\mysql-8.0.29-winx64\data\binlog.000058 > E:\test\result\db.sql

轉(zhuǎn)換成功如下,可以看到刪除 sql 的語(yǔ)句

接下來(lái)只需要將上面的 delete 語(yǔ)句轉(zhuǎn)換為 inert 即可恢復(fù)誤刪數(shù)據(jù),如果需要轉(zhuǎn)換的多可以通過(guò)代碼自定義實(shí)現(xiàn),主要就是將
delete 轉(zhuǎn) insert

6、delete 轉(zhuǎn) insert 恢復(fù)誤刪

通過(guò) vbs 腳本轉(zhuǎn)換 sql 語(yǔ)句,當(dāng)然也可以使用其他的語(yǔ)言,window 執(zhí)行 vbs 不需要額外的環(huán)境,你只需要修改下面 vbs 文件中輸入輸出文件名以及編碼類(lèi)型即可

'==========================
'用VBS實(shí)現(xiàn) MYSQL binglog DELETE 轉(zhuǎn) 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轉(zhuǎn)INSERT==========
'VBS打開(kāi)文本文件
Set oldStream = CreateObject("ADODB.Stream")
oldStream.CharSet = "utf-8"
oldStream.Open
'binLog 生成的 DELETE 原日志文件'
oldStream.LoadFromFile("E:\test\result\db.sql") 
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 object
newStream.WriteText newText
newStream.SaveToFile "mysqllogOK.sql", 2 'DELETE轉(zhuǎn)成INSERT以后的新的SQL文件名
newStream.Close

轉(zhuǎn)換結(jié)果如下,自行選擇新增恢復(fù)數(shù)據(jù)

總結(jié)

到此這篇關(guān)于MySQL恢復(fù)誤刪數(shù)據(jù)的文章就介紹到這了,更多相關(guān)MySQL恢復(fù)誤刪數(shù)據(jù)內(nèi)容請(qǐng)搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關(guān)文章希望大家以后多多支持腳本之家!

相關(guān)文章

最新評(píng)論