更新时间:2024-12-23 GMT+08:00
使用示例
- 设置参数:idle_transaction_timeout=10,idle_readonly_transaction_timeout=0,idle_write_transaction_timeout=0
- 只读事务
mysql> begin; Query OK, 0 rows affected (0.00 sec)
在“idle_transaction_timeout”设置的10s范围以外执行一次查询操作,结果如下:
mysql> select * from t1; ERROR 2013 (HY000): Lost connection to MySQL server during query
- 读写事务
mysql> select * from t1; +---------+ | col_int | +---------+ | 1 | +---------+ 1 row in set (0.00 sec) mysql> begin; Query OK, 0 rows affected (0.00 sec) mysql> insert into t1 values(2); Query OK, 1 row affected (0.00 sec)
在“idle_transaction_timeout”设置的10s范围以外执行一次查询操作,结果如下:
mysql> select * from t1; ERROR 2013 (HY000): Lost connection to MySQL server during query
新建一个连接,执行查询语句,结果如下,表示此时事务已经回滚。
mysql> select * from t1; +---------+ | col_int | +---------+ | 1 | +---------+ 1 row in set (0.00 sec)
- 只读事务
- 设置参数:idle_write_transaction_timeout=15
- 读写事务
mysql> select * from t1; +---------+ | col_int | +---------+ | 2 | +---------+ 1 row in set (0.00 sec) mysql> begin; Query OK, 0 rows affected (0.00 sec) mysql> insert into t1 values(3); Query OK, 1 row affected (0.00 sec)
在“idle_write_transaction_timeout”设置的15s范围以外执行一次查询操作,结果如下:
mysql> select * from t1; ERROR 2013 (HY000): Lost connection to MySQL server during query
新建一个连接,执行查询语句,结果如下,表示此时事务已经回滚。
mysql> select * from t1; +---------+ | col_int | +---------+ | 2 | +---------+ 1 row in set (0.01 sec)
- 读写事务
- 设置参数:idle_readonly_transaction_timeout=15
- 只读事务
mysql> begin; Query OK, 0 rows affected (0.00 sec)
在“idle_readonly_transaction_timeout”设置的15s范围以外执行一次查询操作,结果如下:
mysql> select * from t1; ERROR 2013 (HY000): Lost connection to MySQL server during query
- 只读事务
父主题: 主动终止空闲事务