公众号:架构师与哈苏
关注公众号进入it交流群! 公众号:架构师与哈苏 不定时都会推送一些实用的干货。。。

查看mysql是否开启binlog

show variables like '%log_bin%';

查询文件目录

show variables like '%datadir%';

查看所有binlog日志文件列表

show master logs;

刷新日志,开启一个新的编号

flush logs

清空所有binlog日志命令

reset master

查看binlog文件内容,使用查看工具

方法一:
mysqlbinlog --no-defaults -vv --base64-output=decode-rows binlog.000001

方法二:
show binlog events in 'binlog.000001'

恢复

# 恢复整个binlog中的数据
mysqlbinlog --no-defaults binlog.000001|mysql -u root -p test

# 恢复指定位置数据
mysqlbinlog --no-defaults --start-position=612 --stop-position=759 binlog.000001|mysql -u root -p test

# 恢复指定时间段数据
mysqlbinlog --no-defaults --start-datetime="2022-07-05 11:32:42" --stop-datetime="2022-07-05 11:32:53"  binlog.000001|mysql -u root -p test

--start-position=50
指定了pos的点从50开始

-stop-position=100
指定了pos的点从100结束

--start-date="2019-03-02 11:55:00"
指定了从这个时间开始

--stop-date="2018-03-02 12:00:00"
指定了从这个时间结束

--no-defaults
可以避免 my.cnf 里配了 [client] 某些 mysqlbinlog 没有的参数导致 mysqlbinlog 失败

-vv
从行格式中重建伪SQL(带注释)


--base64-output=decode-rows
指定为decode-rows表示不显示binglog二进制部分

--database=test
指定数据库

--skip-gtids
不保留 GTID 事件信息,这样回放 binlog 时会跟执行新事物一样,生成新的 GTID
posted on 2022-07-05 11:51  公众号/架构师与哈苏  阅读(181)  评论(0编辑  收藏  举报