您的位置:首页 > 其它

手动创建binary log files和手动编辑binary log index file会有什么影响

2018-01-13 17:34 537 查看
基本环境:官方社区版MySQL 5.7.19

一、了解Binary Log结构

1.1、High-Level Binary Log Structure and Contents

• Binlog包括binary log files和index file
• 每个binary log文件的前4字节是Magic Number,紧接着是一组描述数据修改的Events
  • The magic number bytes are 0xfe 0x62 0x69 0x6e = 0xfe 'b''i''n'
  • 每个Event包括header bytes和data bytes
    header bytes:Event类型,什么时候,由哪个server生成等信息
    data bytes:特定的数据修改
  • 第一个Event是Description Event,描述文件的格式版本
  • 其他Events按照binlog_version(1、3、4)进行记录
  • 最后一个Event是Log-rotation Event,指定下一个binary log的文件名称
• index文件里面是当前binary log的一个列表

1.2、Binary Log结构示意图

[root@ZST1 logs]# mysqlbinlog -v --base64-output=decode-rows mysql-bin.9223372036854775808
/*!50530 SET @@SESSION.PSEUDO_SLAVE_MODE=1*/;
/*!50003 SET @OLD_COMPLETION_TYPE=@@COMPLETION_TYPE,COMPLETION_TYPE=0*/;
DELIMITER /*!*/;
# at 4
#180112 15:57:18 server id 1323308  end_log_pos 123 CRC32 0x798b200f    Start: binlog v 4, server v 5.7.19-log created 180112 15:57:18
# Warning: this binlog is either in use or was not closed properly.
# at 123
#180112 15:57:18 server id 1323308  end_log_pos 154 CRC32 0xf3252c32    Previous-GTIDs
# [empty]
# at 154
#180112 15:57:18 server id 1323308  end_log_pos 214 CRC32 0x6054f256    Rotate to mysql-bin.9223372036854775808  pos: 4
SET @@SESSION.GTID_NEXT= 'AUTOMATIC' /* added by mysqlbinlog */ /*!*/;
DELIMITER ;
# End of log file
/*!50003 SET COMPLETION_TYPE=@OLD_COMPLETION_TYPE*/;
/*!50530 SET @@SESSION.PSEUDO_SLAVE_MODE=0*/;
[root@ZST1 logs]#


View Code
解析binlog可以在末尾看到Rotate to mysql-bin.9223372036854775808 pos: 4
也就是说再怎么切,也只能切到9223372036854775808,这个文件感觉有点不太正常,不受max_binlog_size限制,解析出的日志莫名不完整~
恢复原始:手工删除 mysql-bin.2147483647 这类大文件,然后修改 mysql-bin.index;或者直接清空logs文件夹,再重新启动数据库服务

四、参考文档

MySQL binlog后面的编号最大是多大:http://wubx.net/mysql-binlog-max-sequence/
High-Level Binary Log Structure and Contents:https://dev.mysql.com/doc/internals/en/binary-log-structure-and-contents.html
Binary Log Versions:https://dev.mysql.com/doc/internals/en/binary-log-versions.html
Event Structure:https://dev.mysql.com/doc/internals/en/event-structure.html
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: