How can I stop a running MySQL query?


In order to stop a running MySQL query, we can use the KILL command with process id. The syntax is as follows −

kill processId;

Or you can stop a running MySQL query with the help of below syntax −

call mysql.rds_kill(queryId);

Let us first get the processId with the help of show command. The query is as follows −

mysql> show processlist;

Here is the output with the list of processes −

+----+-----------------+-----------------+----------+---------+--------+------------------------+------------------+
| Id |  User           | Host            | db       | Command | Time   | State                  | Info             |
+----+-----------------+-----------------+----------+---------+--------+------------------------+------------------+
| 4  | event_scheduler | localhost       | NULL     | Daemon  | 221718 | Waiting on empty queue | NULL             |
| 47 | root            | localhost:60722 | business | Query   | 0      | starting               | show processlist |
+----+-----------------+-----------------+----------+---------+--------+------------------------+------------------+
2 rows in set (0.03 sec)

Here, two processes are running in MySQL and if you want to stop one of them, then you can use above syntax with the specific id using “KILL”

The query is as follows −

mysql> kill 47;
ERROR 1317 (70100): Query execution was interrupted

Alternatively, you can do this with mysql.rds_kill(id). The query is as follows −

mysql> CALL mysql.rds_kill(47);
ERROR 2013 (HY000): Lost connection to MySQL server during query

Updated on: 30-Jul-2019

427 Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements