心寄笔端 附庸风雅

甘草的技术博客

  博客园 :: 首页 :: 博问 :: 闪存 :: 新随笔 :: 联系 :: 订阅 订阅 :: 管理 ::

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

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

class Log_event_header

class Log_event_footer

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

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

 

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

然后我们就可以一个Event,一个Event的读取了(格式基本就是一段一段的了。)

用Python解析Event header

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

 

查看当前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

 

posted on 2015-07-31 15:07  甘草  阅读(1622)  评论(0编辑  收藏  举报
Baidu
Google
心寄笔端
TEST
以后我会加上Power By的,先别介意