时间:2021-07-01 10:21:17 帮助过:8人阅读
一、开启binlog
在[mysqld] 区块设置/添加 log-bin=mysql-bin 确认是打开状态(值 mysql-bin 是日志的基本名或前缀名);
二、通过mysql的变量配置表,查看二进制日志是否已开启
mysql> show variables like ‘log_%‘; +----------------------------------------+---------------------------------------+ | Variable_name | Value | +----------------------------------------+---------------------------------------+ | log_bin | ON | ------> ON表示已经开启binlog日志 | log_bin_basename | /usr/local/mysql/data/mysql-bin | | log_bin_index | /usr/local/mysql/data/mysql-bin.index | | log_bin_trust_function_creators | OFF | | log_bin_use_v1_row_events | OFF | | log_error | /usr/local/mysql/data/martin.err | | log_output | FILE | | log_queries_not_using_indexes | OFF | | log_slave_updates | OFF | | log_slow_admin_statements | OFF | | log_slow_slave_statements | OFF | | log_throttle_queries_not_using_indexes | 0 | | log_warnings | 1 | +----------------------------------------+---------------------------------------+
三、binlog日志内容查看
binlog日志有二种查看方式,具体如下:
1、mysql查看binlog
mysql> show binlog events; #只查看第一个binlog文件的内容 mysql> show binlog events in ‘mysql-bin.000002‘;#查看指定binlog文件的内容 mysql> show binary logs; #获取binlog文件列表 mysql> show master status; #查看当前正在写入的binlog文件
2、使用mysqlbinlog工具
mysqlbinlog是一个查看mysql二进制日志的工具,可以把mysql上面的所有操作记录从日志里导出,这个工具默认的安装路径为:/usr/local/mysql/bin/mysqlbinlog
可以通过find / -name "mysqlbinlog"命令查找mysqlbinlog的工具路径。
基于开始/结束时间:
/usr/local/mysql/bin/mysqlbinlog --start-datetime="2013-03-01 00:00:00" --stop-datetime="2014-03-21 23:59:59" /usr/local/mysql/var/mysql-bin.000007 -r test2.sql
参见:http://www.yaoguangkeji.com/a_4brldYkw.html
http://www.boydwang.com/2014/03/use-mysqlbinlog-to-restore-accidentally-deleted-data/
http://blog.csdn.net/nuli888/article/details/52106910
https://www.cnblogs.com/martinzhang/p/3454358.html
mysql查看binlog日志
标签:-name local star 进制 store 结束 时间 数据查询 文件