Mysql update誤操作恢復

stephenjwq發表於2018-12-12

update忘加where條件誤操作
從binlog找到那條語句:
[root@xxx]#/usr/local/mysql/bin/mysqlbinlog --no-defaults -v -v --base64-output=DECODE-ROWS mysq-bin.xxxx | grep -B 15 'failure' | more /*|*/;

匯出binlog
[root@xxx]#/usr/local/mysql/bin/mysqlbinlog --no-defaults -v -v --base64-output=DECODE-ROWS mysq-bin.xxxx | sed -n '/# at 249/,/COMMIT/p' > /opt/1.txt

將binlog轉換為sql語句
[root@xxx]#sed '/WHERE/{:a;N;/SET/!ba;s/\([^\n]*\)\n\(.*\)\n\(.*\)/\3\n\2\n\1/}' 1.txt
| sed -r '/WHERE/{:a;N;/@4/!ba;s/### @2.*//g}'
| sed 's/### //g;s/\/\*.*/,/g'
| sed '/WHERE/{:a;N;/@1/!ba;s/,/;/g};s/#.*//g;s/COMMIT,//g'
| sed '/^$/d' > ./recover.sql

mysql> source /opt/recovery.sql
mysql> select * from test;


來自 “ ITPUB部落格 ” ,連結:http://blog.itpub.net/9522838/viewspace-2284994/,如需轉載,請註明出處,否則將追究法律責任。

相關文章