show VARIABLES LIKE 'log_bin'
show binary logs;
windows mysql5.7.10环境:
1.开启日志,修改my.ini.(5.7.3版本以上要设置server_id)
log-bin=E:\phpstudy\MySQL\data\mysql-bin\mysql-bin
binlog-format=Row
server_id = 1234
ubuntu mysql5.7.10环境
1.开启日志,修改/etc/mysql/mysql.conf.d/mysqld.cnf
binlog-format=Row
server-id = 1
log_bin = /var/log/mysql/mysql-bin.log #日志路径
expire_logs_days = 10
max_binlog_size = 100M
然后重启数据库。发现会多了几个文件(mysql-bin.000001类似的文件)
show master status;#当前日志
show binlog events in 'mysql-bin.000001';#查看日志内容
show VARIABLES LIKE "%binlog_rows_query_log_events%";
set binlog_rows_query_log_events = on;#可以查看sql
使用mysqlbinlog查看日志内容
mysqlbinlog mysql-bin.000040 -v #查看全部内容
mysqlbinlog --database=test mysql-bin.000001 -v #查看指定数据库内容
mysqlbinlog --start-datetime="2018-04-02 17:20:00" --stop-datetime="2018-04-02 17:30:00" mysql-bin.000040 -v
导出到sql文件: