MySQL binlog的格式解析

我搜集到了一些资料,对理解代码比较有帮助。html

在头文件中binlog_event.h中,有描述mysql

class Log_event_headergit

class Log_event_footergithub

参见【Mysteries of the Binary Log Presentation.pdf】sql

代码见【mysql-5.7.6-m16_src.zip】xcode

 

MySQL binlog头4个字节:BINLOG_HEADER = b'\xfe\x62\x69\x6e'函数

而后咱们就能够一个Event,一个Event的读取了(格式基本就是一段一段的了。)ui

用Python解析Event header.net

struct.unpack("=IBIIIH", header), 获得的分别是timestamp, typecode, server_id, event_len, next_pos, flasgcode

 

查看当前binlog的设置

show variables like '%log%';

set global binlog_format='row'   ; 'statement'  or   'mixed'

 

binlog格式解析相关的文章和代码:

http://www.tuicool.com/articles/6RvUnqV

http://www.oschina.net/code/snippet_915111_16360

http://www.xcoder.cn/html/Database/mysql/2013/0526/9191.html

http://blog.csdn.net/wyzxg/article/details/7412777

【解析binlog格式,网上能找到有用的文章并非不少,代码就更少了,我这份代码能够供你们参考。】

https://github.com/healerkx/PySQLKits/tree/master/scripts/mysqlbinlog

 

细节

1. Decimal在binlog中的的存储格式:

我写到field_descriptor.py里面的 decimal_descriptor, parse()函数, 时间久了,之后我再更新它的解析细节描述。

 

更多看我Rust的实现版本吧,相对于Python的版本fix了一些问题,占用资源确定又少了。

https://github.com/healerkx/mysqlbinlog-rs

相关文章
相关标签/搜索