You need to enable JavaScript to run this app.
文档中心
云数据库 MySQL 版

云数据库 MySQL 版

复制全文
下载 pdf
性能
大事务提交 binlog 优化
复制全文
下载 pdf
大事务提交 binlog 优化
本文介绍火山引擎云数据库 MySQL 版提供的大事务提交 binlog 优化功能的相关信息。​
背景信息​
在 MySQL 里,大事务提交时常常会让整个实例的写入操作受阻。这是因为大事务会产生很多 binlog 事件,这些事件会先存到当前会话的临时缓存中,提交时再复制到 binlog 文件里。这个过程会产生大量的输入输出操作,并且会一直给 binlog 加锁,使得其他事务没办法提交。火山引擎云数据库 MySQL 版针对这种情况做了优化,先把大事务产生的 binlog 事件写到临时文件中,提交时不用复制,直接把临时文件重命名为正式的 binlog 文件,这样大大提高了大事务提交的效率,保证不会影响其他事务的提交。​
支持版本​
  • MySQL 5.7 版本,且内核版本为 MySQL 5.7.32_20250615 及以上。​
  • MySQL 8.0 版本,且内核版本为 MySQL 8.0.32_20250615 及以上。​
  • MySQL 8.4 版本,且内核小版本为 MySQL 8.4.7_20260415 及以上。​
说明​
您可通过查看实例信息查看实例的内核小版本。如您实例的内核小版本未在受支持的内核小版本范围内,可手动升级实例内核小版本。​
使用说明​
可以通过如下参数使用大事务提交 binlog 优化功能。​
​
名称​
类型​
是否需要重启以生效​
取值范围​
默认值​
级别​
说明​
loose_enable_binlog_large_trans_opt​
bool​
否​
[ON|OFF]​
OFF​
Global​
是否打开大事务提交 binlog 优化功能。​
loose_binlog_large_trans_threshold​
integer​
否​
[20971520- 18446744073709551615]​
268435456(256 MiB)​
Global​
设定作为大事务进行 binlog 提交优化的事务 binlog 事件大小的阈值。事务 binlog 事件大小大于该参数的设定值时,此事务会被作为大事务进行 binlog 提交优化。该参数的单位为字节。​
​
​
使用示例​
  1. 在 5.7 实例上, 按如下 SQL,创建一张大表。​
  • ​
    create table large_table1(id bigint not null auto_increment primary key, a varchar(10000));​
    ​
    insert into large_table1(a) select repeat('a', 10000);​
    ​
    // 不断 insert ... select ...​
    ​
    MySQL [test]> insert into large_table1(a) select a from large_table1;​
    Query OK, 65536 rows affected (8.439 sec)​
    Records: 65536 Duplicates: 0 Warnings: 0​
    ​
    // 继续 insert ... select ...​
    ​
​
  1. 确认大事务提交 binlog 优化功能为关闭状态,即确认 loose_enable_binlog_large_trans_opt 的值为 OFF后,执行下面的 SQL 并记录执行时长。​
  • ​
    MySQL [test]> create table tmp like large_table1;​
    Query OK, 0 rows affected (0.006 sec)​
    ​
    MySQL [test]> begin;​
    Query OK, 0 rows affected (0.003 sec)​
    ​
    MySQL [test]> insert into tmp select * from large_table1 limit 672000;​
    Query OK, 672000 rows affected (2 min 0.550 sec)​
    Records: 672000 Duplicates: 0 Warnings: 0​
    ​
    MySQL [test]> commit;​
    Query OK, 0 rows affected (26.278 sec)​
    ​
  • 在事务提交前 tmp 表的 binlog 缓存达到 6.3 GiB;事务提交用时 26.278 sec,期间其他的写入事务完全被阻塞。​
  1. 修改参数 loose_enable_binlog_large_trans_opt 的值为 ON,打开大事务提交 binlog 优化功能。再次执行步骤 2 的 SQL 并记录执行时长。​
  • ​
    MySQL [test]> create table tmp1 like large_table1;​
    Query OK, 0 rows affected (0.006 sec)​
    ​
    MySQL [test]> begin;​
    Query OK, 0 rows affected (0.003 sec)​
    ​
    MySQL [test]> insert into tmp1 select * from large_table1 limit 672000;​
    Query OK, 672000 rows affected (2 min 0.514 sec)​
    Records: 672000 Duplicates: 0 Warnings: 0​
    ​
    MySQL [test]> commit;​
    Query OK, 0 rows affected (0.008 sec)​
    ​
  • 开启大事务提交 binlog 优化功能后,事务提交用时 0.008 sec。​
参考信息​
以下是在 5.7 实例上,针对不同大小事务,开启和关闭大事务提交 binlog 优化功能提交事务用时。​
说明​
以下数据仅供参考,不作为大事务提交 binlog 优化功能的性能数据。​
​
事务 binlog 大小​
开启优化​
关闭优化​
800 MiB​
0.138 sec​
2.351 sec​
1.6 GiB​
0.130 sec​
6.749 sec​
3.2 GiB​
0.097 sec​
12.741 sec​
6.4 GiB​
0.165 sec​
25.508 sec​
​
​
​
最近更新时间:2026.08.27 11:24:30
这个页面对您有帮助吗?
有用
有用
无用
无用