How can I stop a MySQL query if it takes too long?

后端 未结 9 1597
野趣味
野趣味 2020-12-02 09:22

Is it possible to timeout a query in MySQL?

That is, if any query exceeds the time I specify, it will be killed by MySQL and it will return an error instead of waiti

9条回答
  •  暗喜
    暗喜 (楼主)
    2020-12-02 09:51

    I thought it has been around a little longer, but according to this,

    MySQL 5.7.4 introduces the ability to set server side execution time limits, specified in milliseconds, for top level read-only SELECT statements.

    SELECT 
    MAX_STATEMENT_TIME = 1000 --in milliseconds
    * 
    FROM table;
    

    Note that this only works for read-only SELECT statements.

提交回复
热议问题