MySQL Binlog解析(2)

一、TABLE_MAP_EVENT

Used for row-based binary logging beginning with MySQL 5.1.5.The TABLE_MAP_EVENT defines the structure if the tables that are about to be changed.

用于从MySQL 5.1.5开始的基于行的二进制日志记录。每个ROW_EVENT之前都有一个TABLE_MAP_EVENT,用于描述表的内部ID和结构定义。

1)触发条件

 # ROW格式中每个ROW_EVENT之前

2)存储格式

1、事件头,占用19个字节。2、事件体部分: 固定数据部分: # table id:6 bytes //6个字节存储table id # 2 bytes:Reserved for future use //2个字节保留未来使用 可变数据部分: # 1 byte. The length of the database name. //数据库名长度:1字节 # Variable-sized. The database name (null-terminated). //数据库名:可变长度 # 1 byte. The length of the table name. //表长度:1字节 # Variable-sized. The table name (null-terminated). //表名:可变长度 # Packed integer. The number of columns in the table. //表的行数: # Variable-sized. An array of column types, one byte per column. To find the meanings of these values, look at enum_field_types in the mysql_com.h header file. //列类型数组,每一列1个字节 # Packed integer. The length of the metadata block. //元数据块的长度 # Variable-sized. The metadata block; see log_event.h for contents and format. //元数据块 # Variable-sized. Bit-field indicating whether each column can be NULL, one bit per column. For this field, the amount of storage required for N columns is INT((N+7)/8) bytes. //位字段,指示每个列是否可以为空,每个列一位。如果表有N列,需要:INT((N+7)/8) 字节

3)实战分析

结合hexdump出来的数据和mysqlbinlog解析出的日志进行分析:

-------公有事件头--------1、timestamp(4): 21 2e 0e 5b2、event_type(1):13,十进制19:TABLE_MAP_EVENT = 193、server id(4):5c 27 6b 94 十进制:24900503964、event size(4):2e 00 00 00,十进制:465、log_pos(4):aa 01 00 00 ,十进制:426 也就是end_log_pos=4266、flags(2):00 00,等于0表示该日志文件关闭状态--------固定数据部分(私有事件头)-----1、table id(6):b1 01 00 00 00 00,十进制433,table_id=4332、reserve(2):01 00,十进制:1,未被使用---------可变数据部分(事件体)--------3、db name len(1):06,数据库名占用6个字节,即darren4、db name(6):64 61 72 72 65 6e,查询asci码,对应darren5、006、table name len(1):01,表名占用1个字节7、table name(1):74,asci码对应字母t,即表名是t8、009、column count(1):01,即列的个数110、column type(1):03,表示MYSQL_TYPE_LONG11、column metadata len(1):00,1个字节12、column metadata:无13、null bitmap(1):00,0表没有列可以为NULL,如果是01表示该列可以为NULL14、crc32(4):8f cb 07 7d,代表CRC32=0x7d07cb8f,不在事件体里,可以认为每个事件都存在footer

相关文章