show binlog events

本文介绍了MySQL中SHOW BINLOG EVENTS命令的使用方法及其参数解释,通过实例展示了如何查看二进制日志中的具体事件,包括创建表、插入数据等操作。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

SHOW BINLOG EVENTS [IN 'log_name'] [FROM pos] [LIMIT [offset,] row_count]

用于在二进制日志中显示事件。如果您不指定’log_name’,则显示第一个二进制日志。
LIMIT子句和SELECT语句具有相同的语法。

实验:

mysql> create table tbl (test TEXT);
Query OK, 0 rows affected (0.00 sec)

mysql> insert into tbl values ("hello,Miles");
Query OK, 1 row affected (0.00 sec)

mysql> flush logs;
Query OK, 0 rows affected (0.00 sec)

默认显示的信息显然不符合我们的要求

mysql> show binlog events\G;
*************************** 1. row ***************************
   Log_name: mysql-bin.000001
        Pos: 4
 Event_type: Format_desc
  Server_id: 1
End_log_pos: 107
       Info: Server ver: 5.5.49-log, Binlog ver: 4
*************************** 2. row ***************************
   Log_name: mysql-bin.000001
        Pos: 107
 Event_type: Query
  Server_id: 1
End_log_pos: 276
       Info: grant replication slave,replication client on *.* 
to repl@'192.168.%' identified by 'beijing'
*************************** 3. row ***************************
   Log_name: mysql-bin.000001
        Pos: 276
 Event_type: Rotate
  Server_id: 1
End_log_pos: 319
       Info: mysql-bin.000002;pos=4
3 rows in set (0.00 sec)

找到当前binlog,因为之前的语句中有flush logs,所以执行的命令记录在上一个日志中

mysql> show master status;
+------------------+----------+--------------+------------------+
| File             | Position | Binlog_Do_DB | Binlog_Ignore_DB |
+------------------+----------+--------------+------------------+
| mysql-bin.000007 |      107 |              |                  |
+------------------+----------+--------------+------------------+
1 row in set (0.00 sec)

mysql> show binlog events in 'mysql-bin.000006'\G;
......
   Log_name: mysql-bin.000006
        Pos: 623
 Event_type: Query
  Server_id: 1
End_log_pos: 708
       Info: create database miles
*************************** 7. row ***************************
   Log_name: mysql-bin.000006
        Pos: 708
 Event_type: Query
  Server_id: 1
End_log_pos: 800
       Info: use `miles`; create table tbl (test TEXT)
*************************** 8. row ***************************
   Log_name: mysql-bin.000006
        Pos: 800
 Event_type: Query
  Server_id: 1
End_log_pos: 869
       Info: BEGIN
*************************** 9. row ***************************
   Log_name: mysql-bin.000006
        Pos: 869
 Event_type: Query
  Server_id: 1
End_log_pos: 971
       Info: use `miles`; insert into tbl values ("hello,Miles")
*************************** 10. row ***************************
   Log_name: mysql-bin.000006
        Pos: 971
 Event_type: Xid
  Server_id: 1
End_log_pos: 998
       Info: COMMIT /* xid=1992 */
*************************** 11. row ***************************
   Log_name: mysql-bin.000006
        Pos: 998
 Event_type: Rotate
  Server_id: 1
End_log_pos: 1041
       Info: mysql-bin.000007;pos=4
11 rows in set (0.00 sec)
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值