如何停止正在运行的MySQL查询?
为了停止正在运行的MySQL查询,我们可以使用带有进程ID的KILL命令。语法如下-
kill processId;
或者您可以借助以下语法停止正在运行的MySQL查询-
call mysql.rds_kill(queryId);
让我们首先在show命令的帮助下获取processId。查询如下-
mysql> show processlist;
这是带有进程列表的输出-
+----+-----------------+-----------------+----------+---------+--------+------------------------+------------------+| 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)
在这里,两个进程正在MySQL中运行,如果要停止其中一个进程,则可以使用“ KILL”将上述语法与特定ID结合使用
查询如下-
mysql> kill 47;ERROR 1317 (70100): Query execution was interrupted
或者,您可以使用mysql.rds_kill(id)进行此操作。查询如下-
mysql> CALL mysql.rds_kill(47);ERROR 2013 (HY000): Lost connection to MySQL server during query
以上是 如何停止正在运行的MySQL查询? 的全部内容, 来源链接: utcz.com/z/359778.html