温馨提示×

温馨提示×

您好,登录后才能下订单哦!

密码登录×
登录注册×
其他方式登录
点击 登录注册 即表示同意《亿速云用户服务条款》

解析MySQL binlog --(1)大致结构及event type

发布时间:2020-07-10 11:02:36 来源:网络 阅读:3361 作者:yzs的专栏 栏目:MySQL数据库

1、简介

binlog以事件的形式记录数据库变更情况。通过执行show binlog events in "binlog file"命令可以查看事件

mysql> show binlog events in "mysql-bin.000002";  
+------------------+-----+-------------+-----------+-------------+---------------------------------------------+  
| Log_name         | Pos | Event_type  | Server_id | End_log_pos | Info                                        |  
+------------------+-----+-------------+-----------+-------------+---------------------------------------------+  
| mysql-bin.000002 |   4 | Format_desc |        11 |         120 | Server ver: 5.6.26-debug-log, Binlog ver: 4 |  
| mysql-bin.000002 | 120 | Query       |        11 |         191 | BEGIN                                       |  
| mysql-bin.000002 | 191 | Table_map   |        11 |         236 | table_id: 70 (yzs.t1)                       |  
| mysql-bin.000002 | 236 | Write_rows  |        11 |         280 | table_id: 70 flags: STMT_END_F              |  
| mysql-bin.000002 | 280 | Xid         |        11 |         311 | COMMIT /* xid=9 */                          |  
+------------------+-----+-------------+-----------+-------------+---------------------------------------------+  
5 rows in set (0.00 sec)  
mysql> show binlog events in "mysql-bin.000001";  
+------------------+-----+-------------+-----------+-------------+---------------------------------------------+  
| Log_name         | Pos | Event_type  | Server_id | End_log_pos | Info                                        |  
+------------------+-----+-------------+-----------+-------------+---------------------------------------------+  
| mysql-bin.000001 |   4 | Format_desc |        11 |         120 | Server ver: 5.6.26-debug-log, Binlog ver: 4 |  
| mysql-bin.000001 | 120 | Query       |        11 |         197 | BEGIN                                       |  
| mysql-bin.000001 | 197 | Query       |        11 |         294 | use `yzs`; insert into t1 select 2,2        |  
| mysql-bin.000001 | 294 | Xid         |        11 |         325 | COMMIT /* xid=9 */                          |  
| mysql-bin.000001 | 325 | Stop        |        11 |         348 |                                             |  
+------------------+-----+-------------+-----------+-------------+---------------------------------------------+  
5 rows in set (0.00 sec)

2、binlog事件格式及类型
解析MySQL binlog --(1)大致结构及event type
分为2部分,事件头和事件体。事件头包括:

timestamp:事件开始的执行时间,固定4字节展示是新纪元(epoch time)以来的秒数。

event type:指明该事件的类型

server-id:服务器的server ID

event size:该事件的长度

next-log pos:固定4字节下一个event的开始位置

flag:固定2字节 event flags
#define LOG_EVENT_BINLOG_IN_USE_F 0x1 这个flags表示是否binlog正确的关闭了
..其他标签可参看源码log_event.h

事件体:根据事件类型的不同,包含了不同的信息。

binlog事件类型:
解析MySQL binlog --(1)大致结构及event type
只挑了比较重要的事件类型进行解析。下章节针对每个event类型进行详细解析。

向AI问一下细节

免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:is@yisu.com进行举报,并提供相关证据,一经查实,将立刻删除涉嫌侵权内容。

AI