1. 查看日志开启状态
show variables like 'log_%';
2. 查看日志文件列表
show binary logs;或者show master logs;
3. 查看当前日志index位置
show master status;
4. 查看binlog关键事件
show binlog events [IN 'log_name'] [FROM pos] [LIMIT [offset,] row_count];
例如,show binlog events in 'mysql-bin.000002' from 624 limit 2,10;
5. 提取日志数据(2选1)
1)mysqlbinlog --database=DBName --base64-output=decode-rows --set-charset=utf8 --no-defaults -v mysql-bin.000720 --start-datetime="2018-09-12 18:45:00" --stop-datetime="2018-09-12:18:47:00"(通过时间定位数据区间)
2)mysqlbinlog --database=DBName --base64-output=decode-rows --set-charset=utf8 --no-defaults -v mysql-bin.000720 --start-position=450 --stop-position=900(通过index定位数据区间)
6. 将delete语句转换为insert语句(shell脚本)
sed -n '/###/p' | sed 's/### //g;s/\/\*.*/,/g;s/DELETE FROM/;INSERT INTO/g;s/WHERE/VALUE(/g;' | sed 's/@1=//g'| sed 's/@[1-9]=/,/g' | sed 's/@[1-9][0-9]=/,/g' | sed 's/ \+/ /g'|sed ":a;N;s/\,\n ,/\n,/g;s/\,\n;/);/g;ta"|sed '0,/;/s/;//'|sed '$ s/.$/);/'
标签:数据恢复,show,--,sed,binlog,mysql,日志 From: https://www.cnblogs.com/hyssong/p/17663176.html