文档章节

MySQL binlog之log event

秋风醉了
 秋风醉了
发布于 2016/09/26 16:58
字数 528
阅读 516
收藏 1

精选30+云产品,助力企业轻松上云!>>>

MySQL binlog之log event

概述

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

log event 结构

http://dev.mysql.com/doc/internals/en/event-structure.html

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:

输入图片说明

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:

输入图片说明

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

http://dev.mysql.com/doc/internals/en/event-classes-and-types.html

常见的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.

更多见http://dev.mysql.com/doc/internals/en/event-meanings.html

=====END=====

秋风醉了
粉丝 253
博文 530
码字总数 404430
作品 0
朝阳
程序员
私信 提问
加载中
请先登录后再评论。
gtid_executed和gtid_purged变量是如何初始化的

一、官方释义 1.1、gtidexecuted、gtidpurged https://dev.mysql.com/doc/refman/5.7/en/replication-options-gtids.html#sysvargtidexecuted • gtidexecuted When used with global scope......

osc_6y4us9hc
2018/01/19
3
0
MySQL binlog中的事件类型

Reference: https://www.cnblogs.com/ivictor/p/5780617.html MySQL binlog中的事件类型 MySQL binlog记录的所有操作实际上都有对应的事件类型的,譬如STATEMENT格式中的DML操作对应的是QUE...

osc_51w4wn2j
2019/01/29
5
0
MySQL Binlog 事件介绍篇

原文出处:zhaohui 前言 上一篇文件MySql Binlog初识,对Binlog的参数,格式以及个别事件做了详细介绍,但是Binlog事件数量比较多,上篇文章中没有对所有事件进行介绍;本文将对Binlog的事件...

zhaohui
2017/11/22
0
0
mysql同步复制报Slave can not handle replication events with the checksum that master 错误

mysql同步复制报Slave can not handle replication events with the checksum that master 错误 2014-12-15 15:16:06 wantingtingting 阅读数 3488更多 分类专栏: SQL mysql 版权声明:本文......

Summer-007
2019/11/26
0
0
MySQL binlog event 详解

我也是只菜鸡,blog写的不对或者不严谨的地方还请大伙指出来,我及时改正,免得误人子弟。 实验环境: CentOS7.3.1611 + MySQL社区版 5.7.19 参考: 小菜鸟DBA的微信公众号推送 官方文档: ...

lirulei90
2018/01/12
0
0

没有更多内容

加载失败,请刷新页面

加载更多

VS code 可以做什么?

编写 markdown VS code 真的是非常好用的Markdown编写工具,我用他来编写Markdown的时间甚至比写代码还要多。比如,我每周写的公众号文章。 相关插件: Markdown Markdown Preview Enhanced...

osc_08vvd847
7分钟前
0
0
OC项目转Swift指南

运行环境:Xcode 11.1 Swift5.0 最近参与的一个项目需要从Objective-C(以下简称OC)转到Swift,期间遇到了一些坑,于是有了这篇总结性的文档。 如果你也有将OC项目Swift化的需求,可以作为参...

osc_p6dyctjv
8分钟前
0
0
A Bug's Life POJ - 2492

A Bug's Life Background Professor Hopper is researching the sexual behavior of a rare species of bugs. He assumes that they feature two different genders and that they only inte......

osc_gccs85s0
9分钟前
0
0
Go语言编程 — 项目规范

目录 文章目录 目录 项目布局(Project Layout)规范 程序核心代码目录 /cmd(Command) /pkg(Package) /internal /vendor 常规目录 /configs /init /scripts /build /deployments /test ...

osc_hdksnrrg
9分钟前
11
0
通过Windows Visual Studio远程调试WSL2中的.NET Core Linux应用程序

最近两天在Linux中调试.NET Core应用程序,同时我发现在Linux中调试.NET Core应用程序并不容易。一直习惯在Visual Studio中进行编码和调试。现在我想的是可以简单快速的测试.NET Core应用在L...

osc_jklrr90y
10分钟前
0
0

没有更多内容

加载失败,请刷新页面

加载更多

返回顶部
顶部