深圳全飞鸿

 找回密码
 立即注册
搜索
热搜: 活动 交友 discuz
查看: 679|回复: 1
打印 上一主题 下一主题

mysql常用的binlog日志操作命令

[复制链接]

104

主题

171

帖子

1179

积分

管理员

Rank: 9Rank: 9Rank: 9

积分
1179
跳转到指定楼层
楼主
发表于 2019-6-16 21:33:05 | 只看该作者 回帖奖励 |倒序浏览 |阅读模式
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';
复制代码


回复

使用道具 举报

104

主题

171

帖子

1179

积分

管理员

Rank: 9Rank: 9Rank: 9

积分
1179
沙发
 楼主| 发表于 2019-6-23 17:36:37 | 只看该作者
这里详解一下

  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.
回复 支持 反对

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

QQ|Archiver|手机版|小黑屋|nagomes  

GMT+8, 2025-5-5 08:02 , Processed in 0.024463 second(s), 20 queries .

Powered by Discuz! X3.2

© 2001-2013 Comsenz Inc.

快速回复 返回顶部 返回列表