Parsing MySQL binlog-- (4) TABLE_MAP_EVENT
1. Introduction
row format binlog file, each ROW_EVENT is preceded by a TABLE_MAP_EVENT, used to describe the table's internal ID and structure definition.
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)
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 byte,TABLE_MAP_EVENT = 19
3) server-id: 0b 00 00 00,4 bytes, i.e. 11
4) event_size: 2d 00 00 00,4 bytes, i.e. the total event size is 45 bytes
5) next-log ps: ec 00 00 00,4 bytes, i.e. 236
6)flag:00 00
---------Private Event Header-------
7) Table ID: 46 00 00 00 00, i.e. table ID is 70
8) flag: 01 00, temporarily unused
-----------------------------------------
9) schema name length: 03, i.e. schema name size is 3 bytes
10)schema name:79 7a 73,yzs
11)00
12) table name length: 02, i.e. table name size is 2 bytes
Table name: 74 31, i.e. table name is t1
14)00
col count: 02, i.e. the number of columns is 2
16)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 };
17) col meta length: 00, 1 byte
18) col meta: None
19) null bitmap: 02, the number of columns is 2, one byte is enough: 0000010, that is, the primary key column cannot be NULL
20) checksum, not in the event body. d8 b9 92 2b
The write_footer function finally calculates checksum and places it after 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 Table_map: `yzs`.` t1` mapped to number 70
You can see the consistency with the binlog file.