读取mysql binlog event_MySQL binlog之log event

MySQL binlog之log event

概述

binlog是mysql以二进制形式打印的日志,它默认不加密,不压缩。每个正常的binlog文件头部,有4个字节的标记,值为0xfe 0x62 0x69 0x6e。LOG_EVENT是binlog里的单位。除去头部的标记,binlog就是一个LOG_EVENT的序列。每个LOG_EVENT都独立单元,没有互相引用的关系,它也有自己的二进制头部,主要是记录了时间戳、类型标记等描述信息。

log event 结构

This section describes the general properties of events as byte sequences as they are written to binary or relay log files.

All events have a common general structure consisting of an event header followed by event data:

17b9c6ac9a232f6f00cdb991def284e3.png

The details about what goes in the header and data parts have changed over time, which gives rise to different versions of the binary log format:

v1: Used in MySQL 3.23

v3: Used in MySQL 4.0.2 though 4.1

v4: Used in MySQL 5.0 and up

下面主要看v4 的结构,v4 event structure:

856e0a88a3fc767f77f21dfb5df20781.png

header length = x bytes

data length = (event_length - x) bytes

fixed data length = y bytes variable data length = (event_length - (x + y)) bytes

x is given by the header_length field in the format description event (FDE). Currently, x is 19, so the extra_headers field is empty.

y is specific to the event type, and is given by the FDE. The fixed-part length is the same for all events of a given type, but may vary for different event types.

The fixed part of the event data is sometimes referred to as the "post-header" part. The variable part is sometimes referred to as the "payload" or "body."

log event type

常见的log event type

QUERY_EVENT

Written when an updating statement is done.

STOP_EVENT

Written when mysqld stops.

ROTATE_EVENT

Written when mysqld switches to a new binary log file.

This occurs when someone issues a FLUSH LOGS statement or the current binary log file becomes too large. The maximum size is determined by max_binlog_size.

RAND_EVENT

Written every time a statement uses the RAND() function; precedes other events for the statement. Indicates the seed values to use for generating a random number with RAND() in the next statement. This is written only before a QUERY_EVENT and is not used with row-based logging.

XID_EVENT

Generated for a commit of a transaction that modifies one or more tables of an XA-capable storage engine. Normal transactions are implemented by sending a QUERY_EVENT containing a BEGIN statement and a QUERY_EVENT containing a COMMIT statement (or a ROLLBACK statement if the transaction is rolled back).

WRITE_ROWS_EVENT

Used for row-based binary logging. This event logs inserts of rows in a single table.

=====END=====

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值