Parsing MySQL Binlog--(4) Table_map_event

Source: Internet
Author: User

1. Introduction

In the row format of the Binlog file, each row_event has a table_map_event that describes the internal ID and structure definition of the table.

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 */| | mysql-bin.000002 | 311 |        Query | 11 |        382 | BEGIN | | mysql-bin.000002 | 382 |        Table_map |         11 | 427 | Table_id:70 (YZS.T1) | | mysql-bin.000002 | 427 |        Write_rows |         11 | 471 | Table_id:70 Flags:stmt_end_f | | mysql-bin.000002 | 471 |        Xid |         11 | 502 | COMMIT/* xid=37 */|+------------------+-----+-------------+-----------+-------------+----------- ----------------------------------+9 rows in Set (0.00 sec)

2. table_map_event format definition

3, combined with case description

--------Public Event Header-------

1) timestamp:62 ca A4 5a:4 bytes

2) event_type:13:1 bytes, table_map_event = 19

3) server-id:0b 00 00 00, 4 bytes, 11

4) event_size:2d 00 00 00, 4 bytes, that is, the total event size is 45 bytes

5) Next-log Ps:ec 00 00 00, 4 bytes, 236

6) flag:00 00

----------Private Event Header-------------

7) Table id:46 00 00 00 00 00, that is, the table ID is 70

8) flag:01 00, not used temporarily

----------Event Body-------------------

9) schema name length:03, that is, the schema name size is 3 bytes

) schema name:79 7a 73,yzs

11) 00

Table name length:02, which is a 2-byte size

Table Name:74 31, which is the name of T1

14) 00

Col count:02, that is, the number of columns is 2

Col type:03 03

enum enum_field_types { MYSQL_TYPE_DECIMAL, MYSQL_TYPE_TINY,              MYSQL_TYPE_SHORT,  MYSQL_TYPE_LONG,              MYSQL_TYPE_FLOAT,  MYSQL_TYPE_DOUBLE,              MYSQL_TYPE_NULL,   MYSQL_TYPE_TIMESTAMP,              MYSQL_TYPE_LONGLONG,MYSQL_TYPE_INT24,              MYSQL_TYPE_DATE,   MYSQL_TYPE_TIME,              MYSQL_TYPE_DATETIME, MYSQL_TYPE_YEAR,              MYSQL_TYPE_NEWDATE, MYSQL_TYPE_VARCHAR,              MYSQL_TYPE_BIT,              MYSQL_TYPE_TIMESTAMP2,              MYSQL_TYPE_DATETIME2,              MYSQL_TYPE_TIME2,              MYSQL_TYPE_NEWDECIMAL=246,              MYSQL_TYPE_ENUM=247,              MYSQL_TYPE_SET=248,              MYSQL_TYPE_TINY_BLOB=249,              MYSQL_TYPE_MEDIUM_BLOB=250,              MYSQL_TYPE_LONG_BLOB=251,              MYSQL_TYPE_BLOB=252,              MYSQL_TYPE_VAR_STRING=253,              MYSQL_TYPE_STRING=254,              MYSQL_TYPE_GEOMETRY=255  

(+) Col meta length:00,1 bytes

Col Meta: none

Null bitmap:02, the number of columns is 2, one byte is sufficient: 00000010, that is, the column of the primary key column cannot be null

Checksum, not in the event body. D8 B9 2b
The Write_footer function finally calculates the checksum and puts it behind the event body.

virtual bool write(IO_CACHE* file)  {    return(write_header(file, get_data_size()) ||    write_data_header(file) ||    write_data_body(file) ||    write_footer(file));  }  
# at 191  #180310 21:53:38 server id 11  end_log_pos 236 CRC32 0x2b92b9d8     

You can see the same resolution as in the Binlog file.

Parsing MySQL Binlog--(4) Table_map_event

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.