如何停止正在运行的 MySQL 查询?
我从 Linux shell 连接到 mysql
。我时不时地运行一个太大的 SELECT 查询。它打印又打印,我已经知道这不是我的意思。我想停止查询。
按 Ctrl+C
(几次)会完全终止 mysql
并将我带回 shell,因此我必须重新连接。
是否可以在不杀死 mysql 本身的情况下停止查询?
I connect to mysql
from my Linux shell. Every now and then I run a SELECT
query that is too big. It prints and prints and I already know this is not what I meant. I would like to stop the query.
Hitting Ctrl+C
(a couple of times) kills mysql
completely and takes me back to shell, so I have to reconnect.
Is it possible to stop a query without killing mysql
itself?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(7)
只需添加
KILL QUERY **Id**
则其中 Id 是来自
show processlist
的连接 ID如果您不想在从某些应用程序运行时通常终止连接,
是更好的选择。有关更多详细信息,您可以阅读 mysql 文档 此处
Just to add
KILL QUERY **Id**
where Id is connection id from
show processlist
is more preferable if you are do not want to kill the connection usually when running from some application.
For more details you can read mysql doc here
连接到mysql
显示完整的进程列表:
终止特定查询。这里 id=9255451
如果您的权限被拒绝,请尝试以下 SQL:
Connect to mysql
show full processlist:
Kill the specific query. Here id=9255451
If you get permission denied, try this SQL:
使用 mysqladmin 终止失控查询:
运行以下命令:
然后记下进程 ID。
失控查询不应再消耗资源。
Use
mysqladmin
to kill the runaway query:Run the following commands:
Then note down the process id.
The runaway query should no longer be consuming resources.
如果您有 mysqladmin 可用,您可能会获得查询列表:
然后您可以停止托管长时间运行查询的 mysql 进程:
If you have
mysqladmin
available, you may get the list of queries with:Then you may stop the mysql process that is hosting the long running query:
您需要运行以下命令来终止该进程。
找出要杀死的进程的 id
通过从 id 列中获取值并触发下面的命令,
查询参数指定我们需要杀死查询命令进程。
杀死进程的语法如下
请参考此链接以获取更多信息。
You need to run following command to kill the process.
Find out the id of the process which you wanted to kill by
Take the value from id column and fire below command
Query parameter specifies that we need to kill query command process.
The syntax for kill process as follows
Please refer this link for more information.
这个问题的作者提到,通常只有在
MySQL 打印其输出,表明他意识到执行了错误的查询。
如前所述,在这种情况下,
Ctrl-C
没有帮助。然而,我注意到它将中止当前查询 - 如果您在任何输出之前捕获它
打印。例如:
MySQL 正忙于生成上述两个表的笛卡尔积,并且
你很快就会注意到 MySQL 没有将任何输出打印到屏幕上(该过程
状态是正在发送数据),因此您输入
Ctrl-C
:Ctrl-C
同样可以用于停止UPDATE
> 查询。The author of this question mentions that it’s usually only after
MySQL prints its output that he realises that the wrong query was executed.
As noted, in this case,
Ctrl-C
doesn’t help. However, I’ve noticed that itwill abort the current query – if you catch it before any output is
printed. For example:
MySQL gets busy generating the Cartesian Product of the above two tables and
you soon notice that MySQL hasn't printed any output to screen (the process
state is Sending data) so you type
Ctrl-C
:Ctrl-C
can similarly be used to stop anUPDATE
query.