解析MySQL binlog --(1)大致結構及event type

來源:互聯網
上載者:User

標籤:MySQL binlog

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事件格式及類型

分為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事件類型:

只挑了比較重要的事件類型進行解析。下章節針對每個event類型進行詳細解析。

解析MySQL binlog --(1)大致結構及event type

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.