mysql两阶段提交

  1. 一个事物10000行,两阶段提交是等innodb提交完才写入吗?
1
2
3
4
5
6
7
8
9
10
11
12
13

CREATE TABLE `test_binlog_cache` (
`id` bigint(20) unsigned NOT NULL AUTO_INCREMENT COMMENT '自增主键ID',
`msg` varchar(1024) NOT NULL COMMENT '数据',
PRIMARY KEY (`id`)
) ENGINE=InnoDB AUTO_INCREMENT=0 DEFAULT CHARSET=utf8;

// 产生一个新的binlog日志文件
flush logs;
// 重置所有状态值
flush status;

insert into test_binlog_cache(msg) SELECT REPEAT("xxxxxxxx", 128);
  1. binlog写入时间点.
  1. 若干个大事物同时写不同表,mysql内存使用过大

  2. 只有commit的时候才会写binlog

LOCK BINLOG FOR BACKUP

锁住binlog(Percona server支持,原生不支持),防止新的事物提交。

事物1 事物2
begin;insert ….
LOCK BINLOG FOR BACKUP
commit(Waiting for binlog lock )
UNLOCK BINLOG
执行成功

事物1会处于: Waiting for binlog lock 状态,直到释放binlog锁才会释放成功

binlog日志中的时间戳

单个事物

1
flush logs;begin;select now();select sleep(10);select now();insert into test_binlog_cache(msg) SELECT REPEAT("xxxxxxxx", 128);select sleep(10);select now();insert into test_binlog_cache(msg) SELECT REPEAT("xxxxxxxx", 128);select sleep(10);select now();commit;

mysqlbinlog –base64-output=decode-rows -v mysql-bin.000032

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
BEGIN
/*!*/;
# at 312
#191225 11:41:34 server id 18405 end_log_pos 376 CRC32 0xe3dbfa21 Table_map: `test7`.`test_binlog_cache` mapped to number 10560
# at 376
#191225 11:41:34 server id 18405 end_log_pos 1446 CRC32 0xeb5c669e Write_rows: table id 10560 flags: STMT_END_F
### INSERT INTO `test7`.`test_binlog_cache`
### SET
### @1=54
### @2='xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx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xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx'
# at 2580
#191225 11:41:54 server id 18405 end_log_pos 2611 CRC32 0x562d77a7 Xid = 29723285
COMMIT/*!*/;
SET @@SESSION.GTID_NEXT= 'AUTOMATIC' /* added by mysqlbinlog *//*!*/;
DELIMITER ;

可以看到binlog中的时间戳是生成event日志时的时间戳.并不是commit时的时间戳

多个事物

事物1:

1
flush logs;begin;select now();select sleep(10);select now();insert into test_binlog_cache(msg) SELECT REPEAT("xxxxxxxx", 128);select sleep(10);select now();insert into test_binlog_cache(msg) SELECT REPEAT("xxxxxxxx", 128);select sleep(10);select now();commit;

事物2:

1
select sleep(5);begin;select now();select sleep(10);select now();insert into test_binlog_cache(msg) SELECT REPEAT("xxxxxxxx", 128);select sleep(10);select now();insert into test_binlog_cache(msg) SELECT REPEAT("xxxxxxxx", 128);select sleep(10);select now();commit;

mysqlbinlog –base64-output=decode-rows -v mysql-bin.000033

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
BEGIN
/*!*/;
# at 312
#191225 11:54:38 server id 18405 end_log_pos 376 CRC32 0x3d6d358c Table_map: `test7`.`test_binlog_cache` mapped to number 10560
# at 376
#191225 11:54:38 server id 18405 end_log_pos 1446 CRC32 0x255da85d Write_rows: table id 10560 flags: STMT_END_F
### INSERT INTO `test7`.`test_binlog_cache`
### SET
### @1=60
### @2='xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx'
# at 1446
#191225 11:54:48 server id 18405 end_log_pos 1510 CRC32 0xf0814c50 Table_map: `test7`.`test_binlog_cache` mapped to number 10560
# at 1510
#191225 11:54:48 server id 18405 end_log_pos 2580 CRC32 0x12e6fcae Write_rows: table id 10560 flags: STMT_END_F
### INSERT INTO `test7`.`test_binlog_cache`
### SET
### @1=62
### @2='xxxxxxxxxxxxxxxxxxxxxxxx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end_log_pos 2611 CRC32 0xf1dbf641 Xid = 29725418
COMMIT/*!*/;
# at 2611
#191225 11:55:03 server id 18405 end_log_pos 2659 CRC32 0x8be6c2e5 GTID [commit=yes]
SET @@SESSION.GTID_NEXT= '61bef212-b1ae-11e8-a427-fa163ecf322b:1833632'/*!*/;
# at 2659
#191225 11:54:43 server id 18405 end_log_pos 2732 CRC32 0x45daa78f Query thread_id=6465113 exec_time=0 error_code=0
SET TIMESTAMP=1577246083/*!*/;
BEGIN
/*!*/;
# at 2732
#191225 11:54:43 server id 18405 end_log_pos 2796 CRC32 0x57d6e77f Table_map: `test7`.`test_binlog_cache` mapped to number 10560
# at 2796
#191225 11:54:43 server id 18405 end_log_pos 3866 CRC32 0x2a2fa23e Write_rows: table id 10560 flags: STMT_END_F
### INSERT INTO `test7`.`test_binlog_cache`
### SET
### @1=61
### @2='xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx'
# at 3866
#191225 11:54:53 server id 18405 end_log_pos 3930 CRC32 0x224edaf4 Table_map: `test7`.`test_binlog_cache` mapped to number 10560
# at 3930
#191225 11:54:53 server id 18405 end_log_pos 5000 CRC32 0x70bba4ea Write_rows: table id 10560 flags: STMT_END_F
### INSERT INTO `test7`.`test_binlog_cache`
### SET
### @1=63
### @2='xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx'
# at 5000
#191225 11:55:03 server id 18405 end_log_pos 5031 CRC32 0x94725565 Xid = 29725429
COMMIT/*!*/;
SET @@SESSION.GTID_NEXT= 'AUTOMATIC' /* added by mysqlbinlog *//*!*/;
DELIMITER ;
# End of log file
ROLLBACK /* added by mysqlbinlog */;
/*!50003 SET COMPLETION_TYPE=@OLD_COMPLETION_TYPE*/;
/*!50530 SET @@SESSION.PSEUDO_SLAVE_MODE=0*/;

可以看到

  • binlog的写入是顺序写入的,第一个事物先commit所以先写binlog,但是binlog中的时间戳是和每次插入时间有关,所以能看到前面的binlog时间戳大于后面的binlog时间戳
  • GTID和xid类型的event是在事务执行commit语句时产生的
  • Query、Rows_query、Table_map、Update_rows 类型的event是在事务执行update 语句时产生的
  • 执行begin;语句时未产生任何event

主从复制,relay log中的时间戳和从库binlog中的时间戳

relay log中的时间戳是主库写入的时间戳,这个很好理解,但是从库binlog中的时间戳却还是主库写入的时间戳

mysqlbinlog –base64-output=decode-rows -v mysql-bin.000001

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
use `test7`/*!*/;
SET TIMESTAMP=1577250016/*!*/;
CREATE TABLE `test_binlog_cache` (
`id` bigint(20) unsigned NOT NULL AUTO_INCREMENT COMMENT '自增主键ID',

`msg` varchar(1024) NOT NULL COMMENT '数据',

PRIMARY KEY (`id`)
) ENGINE=InnoDB AUTO_INCREMENT=0 DEFAULT CHARSET=utf8
/*!*/;
# at 657
#191225 11:54:38 server id 18405 end_log_pos 705 CRC32 0x4ad78495 GTID last_committed=0 sequence_number=0 rbr_only=no
SET @@SESSION.GTID_NEXT= '61bef212-b1ae-11e8-a427-fa163ecf322b:1833631'/*!*/;
# at 705
#191225 11:54:38 server id 18405 end_log_pos 768 CRC32 0x28f82f1e Query thread_id=6464423 exec_time=3958 error_code=0
SET TIMESTAMP=1577246078/*!*/;
SET @@session.sql_mode=524288/*!*/;
/*!\C latin1 *//*!*/;
SET @@session.character_set_client=8,@@session.collation_connection=8,@@session.collation_server=45/*!*/;
BEGIN
/*!*/;
# at 768
#191225 11:54:38 server id 18405 end_log_pos 832 CRC32 0x964a2036 Table_map: `test7`.`test_binlog_cache` mapped to number 72
# at 832
#191225 11:54:38 server id 18405 end_log_pos 1902 CRC32 0xada61dcf Write_rows: table id 72 flags: STMT_END_F
### INSERT INTO `test7`.`test_binlog_cache`
### SET
### @1=60
### @2='xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx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xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx'
# at 3036
#191225 11:54:48 server id 18405 end_log_pos 3067 CRC32 0x7981f1f8 Xid = 39
COMMIT/*!*/;
# at 3067
#191225 11:54:43 server id 18405 end_log_pos 3115 CRC32 0x1d339bf4 GTID last_committed=0 sequence_number=0 rbr_only=no
SET @@SESSION.GTID_NEXT= '61bef212-b1ae-11e8-a427-fa163ecf322b:1833632'/*!*/;
# at 3115
#191225 11:54:43 server id 18405 end_log_pos 3178 CRC32 0xf7ae95e2 Query thread_id=6465113 exec_time=3953 error_code=0
SET TIMESTAMP=1577246083/*!*/;
BEGIN
/*!*/;
# at 3178
#191225 11:54:43 server id 18405 end_log_pos 3242 CRC32 0x6e13af16 Table_map: `test7`.`test_binlog_cache` mapped to number 72
# at 3242
#191225 11:54:43 server id 18405 end_log_pos 4312 CRC32 0xf6d98683 Write_rows: table id 72 flags: STMT_END_F
### INSERT INTO `test7`.`test_binlog_cache`
### SET
### @1=61
### @2='xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx'
# at 4312
#191225 11:54:53 server id 18405 end_log_pos 4376 CRC32 0xbcedc966 Table_map: `test7`.`test_binlog_cache` mapped to number 72
# at 4376
#191225 11:54:53 server id 18405 end_log_pos 5446 CRC32 0xa6b6cb88 Write_rows: table id 72 flags: STMT_END_F
### INSERT INTO `test7`.`test_binlog_cache`
### SET
### @1=63
### @2='xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx'
# at 5446
#191225 11:54:53 server id 18405 end_log_pos 5477 CRC32 0x8df2b849 Xid = 42
COMMIT/*!*/;

遇到问题:

  1. mysqlbinlog5.5解析mysql5.7 binlog文件出现
  • 现象

    ERROR: Error in Log_event::read_log_event(): ‘Sanity check failed’, data_len: 31, event_type: 35ERROR: Could not read entry at offset 123: Error in log format or read error.

  • 原因分析
    mysql5.6等高版本binlog文件增加了新的binlog event,如gtid event等。
    mysql5.5版本的mysqlbinlog是识别不了这样的binlog event的。
  • 解决办法:
    使用对应的mysqlbinlog

https://yq.aliyun.com/articles/576704