- 开启binlog
- 设置 my.conf 配置。
vim /etc/my.cnf 添加 log-bin=mysql-bin
2 . 重启mysql 服务
service mysql restart
注意 : 每次服务器(数据库)重启,服务器会调用flush logs;,新创建一个binlog日志!
binlog 文件存放位置。 一般在 /var/lib/mysql 下
使用 ps -ef | mysql 查看 datadir 可以看到存放的路径 。
binlog 的操作
1) show binlog events in 'mysql-bin.000002' G;
2) 指定查询 mysql-bin.000002这个文件,从pos点:624开始查起:
show binlog events in 'mysql-bin.000002' from 624 G;
3) 指定查询 mysql-bin.000002这个文件,从pos点:624开始查起,查询10条(即10条语句)
show binlog events in 'mysql-bin.000002' from 624 limit 10G;