常用binlog日志操作命令

 

查看所有binlog日志列表
mysql> show binary logs;

mysql> show master logs;

mysql> show binlog events in 'testdb-bin.000003';
+-------------------+-----+----------------+-----------+-------------+-----------------------------------+
| Log_name          | Pos | Event_type     | Server_id | End_log_pos | Info                              |
+-------------------+-----+----------------+-----------+-------------+-----------------------------------+
| testdb-bin.000003 |   4 | Format_desc    |  60346035 |         126 | Server ver: 8.0.39, Binlog ver: 4 |
| testdb-bin.000003 | 126 | Previous_gtids |  60346035 |         157 |                                   |
+-------------------+-----+----------------+-----------+-------------+-----------------------------------+
2 rows in set (0.00 sec)

Log_name:binlog文件名
Pos:开始的position *****
Event_type:事件类型
Format_desc:格式描述,每一个日志文件的第一个事件,多用户没有意义,
MySQL识别binlog必要信息
Server_id:mysql服务号标识
End_log_pos:事件的结束位置号 *****
Info:事件内容*****


查看master状态
即最后(最新)一个binlog日志的编号名称,及其最后一个操作事件pos结束点(Position)值
mysql> show master status;

刷新log日志
自此刻开始产生一个新编号的binlog日志文件
mysql> flush logs;

注:每当mysqld服务重启时,会自动执行此命令,刷新binlog日志;
在mysqldump备份数据时加 -F 选项也会刷新binlog日志;

手工清理binlog
PURGE BINARY LOGS BEFORE now() - INTERVAL 3 day;

或者
PURGE BINARY LOGS TO 'mysql-bin.000010';
清空所有binlog日志
此命令切勿随便执行。
mysql> reset master

 

posted @ 2018-08-01 11:49  屠魔的少年  阅读(1679)  评论(0)    收藏  举报