binlog可以查看当前数据库中所有的修改操作,包含数据和结构的修改,所以掌握数据库日志查看是有必要的
通过客户端连接到mysql
查看binlog日志的存储位置(前提是已开启binlog)
-- 查看日志文件列表
SHOW BINARY LOGS;
结果示例
-- 这里返回的是日志文件的路径及前缀名
SHOW VARIABLES LIKE 'log_bin_basename';
结果示例
进入日志目录 执行命令解析日志
# 全量解析mysqlbinlog --base64-output=decode-rows -v mysql-bin.013145
# grep 筛选mysqlbinlog --base64-output=decode-rows -v mysql-bin.013145 |grep 'alert table'
# 转存到新文件mysqlbinlog --base64-output=decode-rows -v mysql-bin.013145 >> output.log
# 筛选并转存到新文件mysqlbinlog --base64-output=decode-rows -v mysql-bin.013145 |grep 'alert table' -C5 >> output.log