Query execution was interrupted, maximum statement execution time exceeded

发布时间 2023-05-23 17:10:29作者: 何苦->

数据库版本:MySQL 5.7.16

报错信息:
ERROR 3024 (HY000): Query execution was interrupted, maximum statement execution time exceeded

检查bug库,发现同样问题:
https://bugs.mysql.com/bug.php?id=83339

原因是max_execution_time设置过小导致。

复现:
将max_execution_time设置成很小的值,执行mysqldump(本质也是执行SELECT)或者SELECT语句:

SET GLOBAL max_execution_time=10;
SELECT * FROM test.t1 LIMIT 100000;
Query execution was interrupted, maximum statement execution time exceeded

解决办法:

  • 通过hints,增大N值(文档说,在hints用法中,将N改为0为无限制,但我测下来不生效,可设置成一个较大值如999999解决)
    SELECT /*+ MAX_EXECUTION_TIME(N) */ * FROM t1 LIMIT 100000;

  • 修改max_execution_time值,将该值设置为较大一个值,或设置为0(不限制)

相关参数:

max_execution_time

该参数5.7.8被添加,单位为ms,动态参数,默认为0。
设置为0时意味着SELECT超时不被设置(不限制超时时间)。

不作用于存储过程中的SELECT语句,并且只作用于只读的SELECT,比如INSERT ... SELECT ... 是不被作用的。