最新国产好看的视频,伊人天堂AV在线,国产Aaaaaa视频,蜜臀视频在线观看一区,人妻av色图,密臀久久久精品影片,青青视频免费观看毛片,久草在线观看视,国产三级精品色情在线

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

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

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

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

# 備份所有數(shù)據(jù)庫
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ù)可以解決,但中文會亂碼(使用下面 vbs 或自定義語言實(shí)現(xià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 的語句

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

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

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

'==========================
'用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打開文本文件
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)容請搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關(guān)文章希望大家以后多多支持腳本之家!

相關(guān)文章

最新評論

阿鲁科尔沁旗| 沧州市| 乌鲁木齐市| 林西县| 奉新县| 福鼎市| 万宁市| 佛冈县| 梅州市| 金堂县| 陆川县| 开封市| 禄丰县| 乌兰县| 清水县| 福贡县| 隆安县| 洪湖市| 克什克腾旗| 凤山县| 登封市| 淄博市| 灵璧县| 肇源县| 凉山| 微博| 武冈市| 黑河市| 宁强县| 五河县| 平泉县| 万盛区| 陵川县| 偏关县| 布拖县| 浑源县| 江西省| 贵定县| 丹阳市| 常德市| 天津市|