【MySQL】mysqldump Error 3024: Query execution was interrupted

神諭丶發表於2018-01-23
資料庫版本:MySQL 5.7.16

mysqldump完整報錯:
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

檢查bug庫,發現同樣問題:
https://bugs.mysql.com/bug.php?id=83339

原因是max_execution_time設定過小導致。


復現:
將max_execution_time設定成很小的值,執行mysqldump(本質也是執行SELECT)或者SELECT語句:

  1. [17:23:01] root@localhost [(none)]SET GLOBAL max_execution_time=10;
  2. Query OK, 0 rows affected (0.00 sec)

  3. [17:23:11] root@localhost [(none)]> SELECT * FROM test.t1 LIMIT 100000;
  4. ERROR 3024 (HY000): Query execution was interrupted, maximum statement execution time exceeded

  5. mysqldump -uxxx -pxxx -S -A > /tmp/a.sql
  6. mysqldump: Error 3024: Query execution was interrupted, maximum statement execution time exceeded when dumping table `$tb_name` at row: 0



解決辦法:
① 通過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 ... 是不被作用的。








個人感覺,這個引數的新增,本意是用於幹掉執行時間過長的SELECT語句,
但這個引數可以被mysqldump所觸發,感覺是一個很雞肋的引數。
最後看了一下,該例項備份失敗,這個引數的確被人配置成了60……



作者微信公眾號(持續更新)

來自 “ ITPUB部落格 ” ,連結:http://blog.itpub.net/29773961/viewspace-2150443/,如需轉載,請註明出處,否則將追究法律責任。

相關文章