Stop mysql query if it is too long

How to automatically terminate long queries in mysql if possible? I understand that I need to optimize queries instead. But now I only have access to the database server.

+2


source to share


4 answers


While you are optimizing your queries, you can interrupt them by killing the corresponding thread .



+1


source


As far as I know, you cannot stop the request after it has completed.

I understand that I need to optimize queries instead.

The way you should go.



Another possibility:

You can look at SQL Transactions if applicable.

+1


source


There is no way in mysql to limit the duration of the query execution and then the timeout. Have a "long request killer" script that catches kills and reports bad requests, for example. looking at the SHOW FULL PROCESSLIST property. You can do this with a stored procedure and call it at a scheduled time or through an application that also connects to mysql on a schedule as well.

0


source


Try to kill a long time of the request process:

   $result = mysql_query("SHOW FULL PROCESSLIST");
    while ($row=mysql_fetch_array($result)) {
        $process_id = $row["Id"];
        if ($row["Time"] > 200 ) {
            $sql="KILL $process_id";
            mysql_query($sql);
        }
    }

      

0


source







All Articles