Parsing MySQL Binlog-(1) Approximate structure and event type

Source: Internet
Author: User

1. Introduction

Binlog records database changes in the form of events. You can view events by executing the show Binlog events in "Binlog file" command

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 event format and type

Divided into 2 parts, event headers and event bodies. Event headers include:

Timestamp: The execution time of the start of the event, the fixed 4-byte display is the number of seconds since the epoch time.

Event Type: Indicates the type of the event

Server-id: Server ID for servers

Event Size: The length of the event

Next-log pos: Fixed 4 bytes Start position of next event

Flag: Fixed 2 bytes Event flags
#define LOG_EVENT_BINLOG_IN_USE_F 0x1 This flags indicates whether BINLOG is properly closed.
.. Other tags can be see source log_event.h

Event Body: Different information is included depending on the type of event.

Binlog Event Type:

Only the more important event types are selected for parsing. The following section parses each event type in detail.

Parsing MySQL Binlog-(1) Approximate structure and event type

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

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.