通過binlog日誌檔案恢復單錶 小技巧

2021-09-04 12:18:17 字數 698 閱讀 4196

場景:某天執行了delete from t1操作忘加where條件,我們需要通過昨天的全量備份+誤操作之前的binlog增量備份,加以恢復。

在通過mysqlbinlog解析時,需要用sed命令去過濾出t1表的insert、delete、update操作,如果binlog檔案很多,並且預設是1g的大小,用這種方法費時費力,很麻煩。

這裡,介紹乙個小技巧,通過授權賬戶去恢復。

我這裡建立乙個使用者hcy,並只授予t1表的select、insert、delete、update許可權,這樣該使用者針對其他表是沒有許可權的,在恢復的時候,加個-f強制就可以忽略後面的錯誤了。

授權賬戶:

grant select, insert, update, delete on `test`.`t1` to 'hcy'@'localhost' identified by '123456';

grant super on `test`.`t1` to 'hcy'@'localhost' identified by '123456';

mysqlbinlog恢復:

mysqlbinlog --no-defaults -vv --base64-output=decode-rows -d test \

mysql-bin.000001 | mysql -s /tmp/mysql3308.sock -uhcy -p123456 -f

通過binlog日誌檔案恢復單錶 小技巧

場景 某天執行了delete from t1操作忘加where條件,我們需要通過昨天的全量備份 誤操作之前的binlog增量備份,加以恢復。在通過mysqlbinlog解析時,需要用sed命令去過濾出t1表的insert delete update操作,如果binlog檔案很多,並且預設是1g的大小...

binlog日誌恢復

檢視mysql是否開啟binlog 進mysql操作 mysql show variables like log bin 查詢binlog檔名 mysql show master status 進mysql操作 查mysqlbinlog工具的位置,每個人都不同自行變更 結果是mysql bin.例如...

通過binlog日誌來恢復誤刪資料時報錯

在mysql5.7的版中使用了gtid複製,可以多執行緒複製,同時也省去了記binlog起始點的煩惱 但是在一次測試環境中通過binlog日誌來恢復誤刪資料時卻耗了不少時間 root mysql 01 tmp mysqlbinlog no defaults mysql bin.000018 star...