深圳全飞鸿

标题: mysql常用的binlog日志操作命令 [打印本页]

作者: admin    时间: 2019-6-16 21:33
标题: mysql常用的binlog日志操作命令
1)查看所有binlog日志列表
  1. mysql> show master logs;
  2. +------------------+-----------+
  3. | Log_name | File_size |
  4. +------------------+-----------+
  5. | mysql-bin.000001 | 149 |
  6. | mysql-bin.000002 | 4102 |
  7. +------------------+-----------+
  8. 2 rows in set (0.00 sec)
复制代码


2)查看master状态,即最后(最新)一个binlog日志的编号名称,及其最后一个操作事件pos结束点(Position)值
  1. mysql> show master status;
  2. +------------------+----------+--------------+------------------+
  3. | File | Position | Binlog_Do_DB | Binlog_Ignore_DB |
  4. +------------------+----------+--------------+------------------+
  5. | mysql-bin.000002 | 4102 | | |
  6. +------------------+----------+--------------+------------------+
  7. 1 row in set (0.00 sec)
复制代码


3)flush刷新log日志,自此刻开始产生一个新编号的binlog日志文件
  1. mysql> flush logs;
  2. Query OK, 0 rows affected (0.13 sec)

  3. mysql> show master logs;
  4. +------------------+-----------+
  5. | Log_name | File_size |
  6. +------------------+-----------+
  7. | mysql-bin.000001 | 149 |
  8. | mysql-bin.000002 | 4145 |
  9. | mysql-bin.000003 | 106 |
  10. +------------------+-----------+
  11. 3 rows in set (0.00 sec)
复制代码


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

4)重置(清空)所有binlog日志
  1. mysql> reset master;
  2. Query OK, 0 rows affected (0.12 sec)

  3. mysql> show master logs;
  4. +------------------+-----------+
  5. | Log_name | File_size |
  6. +------------------+-----------+
  7. | mysql-bin.000001 | 106 |
  8. +------------------+-----------+
  9. 1 row in set (0.00 sec)
复制代码


5)查看指定binlog文件的内容
  1. 只查看第一个binlog文件的内容
  2. mysql> show binlog events;


  3. 查看指定binlog文件的内容
  4. mysql> show binlog events in 'mysql-bin.000002';
复制代码



作者: admin    时间: 2019-6-23 17:36
这里详解一下

  1. SHOW BINLOG EVENTS
  2. [IN 'log_name']
  3. [FROM pos]
  4. [LIMIT [offset,] row_count]
复制代码


Shows the events in the binary log. If you do not specify ‘log_name’, the first binary log is displayed.


各个参数意思如下:

Log_name:The name of the file that is being listed.
Pos:The position at which the event occurs.
Event_type:An identifier that describes the event type.
Server_id:The server ID of the server on which the event originated.
End_log_pos:The position at which the next event begins, which is equal to Pos plus the size of the event.
Info:More detailed information about the event type. The format of this information depends on the event type.





欢迎光临 深圳全飞鸿 (http://www.nagomes.com/disc/) Powered by Discuz! X3.2