You need to enable JavaScript to run this app.
导航
空闲事务清理
最近更新时间:2025.02.28 15:27:02首次发布时间:2025.02.28 15:27:02

云数据库 MySQL 版支持自动清理长时间空闲的事务。本文介绍该功能的使用方法。

使用限制

云数据库 MySQL 版的 8.0.26 版本序列的实例暂不支持该功能。

使用说明

用户可以通过如下参数配置清理空闲事务的时间阈值。

名称类型是否需要重启说明
kill_idle_transactioninteger控制空闲事务的超时时间,单位为秒,默认为0(不生效)

使用示例

  1. 用户设置 kill_idle_transaction 为 5。

  2. 开启事务并写入一条记录。

    mysql> begin;
    Query OK, 0 rows affected (0.00 sec)
    
    mysql> insert into t1 values (1,1,1);
    Query OK, 1 row affected (0.00 sec)
    
    mysql> select * from t1;
    +---+---+------+
    | a | b | c    |
    +---+---+------+
    | 1 | 1 |    1 |
    +---+---+------+
    1 row in set (0.00 sec)
    
  3. 等待 5 秒以上,再次查询时,会发现事务已经被回滚。

    mysql> select * from t1;
    ERROR 2006 (HY000): MySQL server has gone away
    No connection. Trying to reconnect...
    Connection id:    11
    Current database: test
    
    Empty set (0.01 sec)