Binlog是一种二进制格式的文件,理解Binlog二进制格式能够帮助我们进一步理解MySQL的主从复制原理。本文将对Binlog event文件格式进行分析
官方文档:
https://dev.mysql.com/doc/internals/en/binlog-event.html
Binlog文件头
Binlog文件,前4个字节固定为一个Magic Number,十六进制值为fe62696e。
[root@localhost logs]# hexdump -Cv mysql-relay-bin.000004
00000000 fe 62 69 6e df 5d aa 5f 0f 5a 34 00 00 77 00 00 |.bin.]._.Z4..w..|
00000010 00 7b 00 00 00 40 00 04 00 35 2e 37 2e 33 31 2d |.{...@...5.7.31-|
00000020 6c 6f 67 00 00 00 00 00 00 00 00 00 00 00 00 00 |log.............|
源码位置:log_event.h
/* 4 bytes which all binlogs should begin with */
#define BINLOG_MAGIC "\xfe\x62\x69\x6e"
Binlog event:
Binlog文件除了最前面的4个字节之外,就是一个一个的event,event包含两个部分,event header和event data。通常event header大小固定,event data大小可变。
The events contain the actual data that should be shipped from the master to the slave. Depending on the use, different events are sent.
一,Binlog Management
binlog管理类的event包含:
event里包含了实际的数据,需要传送给从库的,根据用处不同,不同的event类型将被发送。
The first event is either a START_EVENT_V3 or a FORMAT_DESCRIPTION_EVENT while the last event is either a