Home > Database > Mysql Tutorial > How to stop a running MySQL query?

How to stop a running MySQL query?

WBOY
Release: 2023-09-25 14:17:05
forward
1426 people have browsed it

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

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

kill processId;
Copy after login

Or you can stop the running MySQL query with the help of the following syntax -

call mysql.rds_kill(queryId);
Copy after login

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

mysql> show processlist;
Copy after login

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)
Copy after login

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 -

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

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
Copy after login

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!

source:tutorialspoint.com
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template