如何停止运行 MySQL 查询?

数据库数据库 2023-08-31 03:31:08 1162
摘要: 在停止MySQL的运行查询之前,我们首先需要看到有多少个进程。使用show命令运行。查询如下所示−mysql>showprocesslist;Afterexecutingtheabovequery,wewillgettheoutputwithsomeid’s.This...

如何停止运行 MySQL 查询?

在停止MySQL的运行查询之前,我们首先需要看到有多少个进程。

使用show命令运行。

查询如下所示 −

mysql> show processlist;

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)

As seen from the above output, the db currently in use is ‘business’. and its id is 8. To stop the 查询命令调用可以与给定的正在运行的进程列表中的ID一起使用。其语法为: is as follows −

call mysql.rds_kill(valueOfGivenIdInProcesslist);

Now, the above syntax is applied to the query and valueOfGivenIdInProcesslist is put as 8. This 下面显示的是 −

mysql> CALL mysql.rds_kill(8);

执行上述查询后,获得以下输出 −

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

当上述查询停止运行时,就会发生这种情况。使用`use`命令来检查它是否有

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

use yourDatabaseName;

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

mysql> use business;

执行上述查询后,获得以下输出 −

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



Database changed
mysql>

因此,很明显查询已经停止,因为消息是“正在尝试...” 在MySQL中,"reconnect…”"的意思是重新连接。同时还显示当前数据库为"none”。经过一段时间后, 时间与数据库的连接恢复。

以上就是如何停止运行 MySQL 查询?的详细内容,更多请关注其它相关文章!