Home  >  Article  >  Database  >  How to stop a running MySQL query?

How to stop a running MySQL query?

WBOY
WBOYforward
2023-09-25 14:17:051382browse

如何停止正在运行的 MySQL 查询?

To stop a running MySQL query, we can use the KILL command with the process ID. The syntax is as follows -

kill processId;

Or you can stop the running MySQL query with the help of the following 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;

This is the output with process list-

+----+-----------------+-----------------+----------+---------+--------+------------------------+------------------+
| 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, if you want to stop one of the processes, then you can use the above Syntax and specific id Use "KILL"

Query as follows - p>

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

Alternatively, you can use mysql.rds_kill(id) to do this. The query is as follows -

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

The above is the detailed content of How to stop a running MySQL query?. For more information, please follow other related articles on the PHP Chinese website!

Statement:
This article is reproduced at:tutorialspoint.com. If there is any infringement, please contact admin@php.cn delete