编程 从库 SQL 线程报 1534/1197:max_binlog_cache_size 不足的复现与修复

2026-09-23 21:02:57

从库 SQL 线程报 1534/1197:max_binlog_cache_size 不足的复现与修复

某客户一套数据库,主库 MySQL 5.7.44,从库 GreatSQL 8.0.32-27。从库 SQL 线程中断,报错如下:

2026-05-07T21:53:42 [ERROR] [MY-010584] [Repl] Slave SQL for channel '': Worker 1 failed executing transaction '18c68804-...:3425315180' at master log binlog.022823, end_log_pos 127908803; Could not execute Write_rows event on table ort.bm_cdr; Writing one row to the row-based binary log failed, Error_code: 1534; handler error HA_ERR_RBR_LOGGING_FAILED; the event's master log FIRST, end_log_pos 627908803, Error_code: MY-001534

报错信息表示:从库在回放事务时失败了,失败位置发生在执行 Write_rows 事件写入从库本地 row-based binlog 的过程中,最终导致 SQL 线程终止。

这说明故障与从库写本地 binlog 有关。该从库开启了本地 binlog,并记录复制回放产生的更新,即开启了 log_slave_updates / log_replica_updates。因此 SQL 线程不仅要把主库事务回放到表中,还要把该事务再次写入从库自己的 binlog;如果从库 binlog 事务缓存上限过小,就可能在回放大事务时失败。

主库允许生成较大的事务 binlog,而从库写本地 binlog 时只允许最多使用 10M 的事务缓存。将从库 max_binlog_cache_size 调整为与主库一致后,再启动 SQL 线程,复制恢复正常。对应的恢复动作可以概括为:调整从库 max_binlog_cache_size,然后执行:

START SLAVE;

另一种报错形态

2026-06-10T11:19:02 [ERROR] [MY-010584] [Repl] Slave SQL for channel '': Worker 1 failed executing transaction '...:85' at master log binlog.000001, end_log_pos 755113733; Could not execute Write_rows event on table test.t1; Multi-statement transaction required more than 'max_binlog_cache_size' bytes of storage; increase this mysqld variable and try again, Error_code: 1197; Writing one row to the row-based binary log failed, Error_code: 1534; handler error HA_ERR_RBR_LOGGING_FAILED; ... Error_code: MY-001197

错误日志明确提示 max_binlog_cache_size 过小,错误码为 1197 + 1534。调大 max_binlog_cache_size,再执行 START SLAVE; 即可解决。

也有只出现 1534 的情况:

... end_log_pos 771775512, Error_code: MY-001534

此时没有 1197,是最后一个单行插入语句生成的 Row Event 过大,超出了当前 binlog Cache 剩余可用空间,导致这一行无法写入,只触发 1534。

以上两种情况,都是由于从库端 max_binlog_cache_size 设置过小导致 SQL 线程异常终止。前者是批量插入,binlog Event 总量超过限制时抛出 1197(缓存超限)并伴随 1534;后者是单个 Row Event 过大,只触发 1534。

排查时可以先看错误码组合:1197 + 1534 表示多语句事务需要的 binlog cache 超过限制;只有 1534 表示单个 Row Event 写本地 binlog 失败。两者都指向 row-based binlog 写入链路,而不是主键冲突或数据不一致。

结论

  1. 从库也会受 binlog cache 限制。只要从库开启本地 binlog 并记录复制更新,SQL 线程回放事务时就要写本地 binlog,因此会受从库 max_binlog_cache_size 限制。
  2. 1534 不是数据冲突。当日志中出现 Writing one row to the row-based binary log failedHA_ERR_RBR_LOGGING_FAILED 时,应优先检查 row-based binlog 写入链路,包括 max_binlog_cache_size、磁盘空间、临时目录、本地 binlog 配置等。

复现该问题的关键前提是:从库开启本地 binlog,并记录复制回放的更新。

复制全文 生成海报 MySQL 主从复制 排障 binlog

推荐文章

程序员茄子在线接单