mysqldump时可能出现的一个error,完整报错如下:
mysqldump: Error: Query execution was interrupted, maximum statement execution time exceeded when trying to dump tablespaces
mysqldump: Error 3024: Query execution was interrupted, maximum statement execution time exceeded when dumping table `$tb_name` at row: 25002
在SELECT时也有可能报该错:
ERROR 3024 (HY000): Query execution was interrupted, maximum statement execution time exceeded
该问题仅发生在5.7.8+的版本
原因是max_execution_time设置过小导致。
将max_execution_time设置成很小的值,执行mysqldump(本质也是执行SELECT)或者SELECT语句即可复现:
- [17:23:01] root@localhost [(none)]> SET GLOBAL max_execution_time=10;
- Query OK, 0 rows affected (0.00 sec)
- [17:23:11] root@localhost [(none)]> SELECT * FROM test.t1 LIMIT 100000;
- ERROR 3024 (HY000): Query execution was interrupted, maximum statement execution time exceeded
- mysqldump -uxxx -pxxx -S xxx.socket -A > /tmp/a.sql
- mysqldump: Error 3024: Query execution was interrupted, maximum statement execution time exceeded when dumping table `$tb_name` at row: 0
可以考虑以下解决方案:
① 通过hints,设置一个较大的N值。
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 … 是不被作用的。