Home > Database > Mysql Tutorial > body text

How do I stop a MySQL query from running?

PHPz
Release: 2023-08-25 09:01:03
forward
1446 people have browsed it

如何停止运行 MySQL 查询?

Before stopping MySQL from running queries, we first need to see how many processes there are.

Run using show command.

The query is as follows −

mysql> show processlist;
Copy after login

After executing the above query, we will get the output with some id's. This is given as follows −

+----+-----------------+-----------------+----------+---------+-------+------------------------+------------------+
| Id | User | Host | db | Command | Time | State | Info |
+----+-----------------+-----------------+----------+---------+-------+------------------------+------------------+
| 4 | event_scheduler | localhost | NULL | Daemon | 71034 | Waiting on empty queue |
NULL |
| 8 | Manish | localhost:53496 | business | Query | 0 | starting |show processlist|
+----+-----------------+-----------------+----------+---------+-------+------------------------+------------------+
2 rows in set (0.00 sec)
Copy after login

As seen from the above output, the db currently in use is 'business'. and its id is 8. To stop the Query command calls can be used with an ID given a list of running processes. Its syntax is: is as follows −

call mysql.rds_kill(valueOfGivenIdInProcesslist);
Copy after login

Now, the above syntax is applied to the query and valueOfGivenIdInProcesslist is put as 8. This Shown below is −

mysql> CALL mysql.rds_kill(8);
Copy after login

After executing the above query, I get the following output −

ERROR 2013 (HY000): Lost connection to MySQL server during query
Copy after login

This happens when the above query stops running. Use the `use` command to check if it has

stopped or not. The syntax for that is as follows −

use yourDatabaseName;
Copy after login

The above syntax is applied to the mydatabase name ‘business’ in the system. The query is as follows −

mysql> use business;
Copy after login

After executing the above query, I get the following output −

No connection. Trying to reconnect...
Connection id: 10
Current database: *** NONE ***



Database changed
mysql>
Copy after login

So, it is obvious that the query has stopped because the message is "Trying..." In MySQL, "reconnect..."" means to reconnect. It also displays the current database as "none". After a period of time, Time for the connection to the database to be restored.

The above is the detailed content of How do I stop a MySQL query from running?. 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
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!