MySQL 会话 - 终止查询以解锁表
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/11523884/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
MySQL Session - Kill query to unlock table
提问by user1259132
A query has locked a table in MySQL. How can the running query's session be killed to unlock the table?
查询已锁定 MySQL 中的一个表。如何终止正在运行的查询的会话以解锁表?
I do not know to view the active sessions/processes in MySQL. How can I this in PuTTY?
我不知道在 MySQL 中查看活动会话/进程。我怎么能在 PuTTY 中做到这一点?
回答by Mike Brant
Go into PuTTY, and then log into MySQL. Run the following in MySQL:
进入 PuTTY,然后登录 MySQL。在 MySQL 中运行以下命令:
show processlist;
That will show a list of all running processes. You will probably be able to find the query that is locking your tables as it will likely be the longest running query with a bunch of other queries waiting for the lock release. Make a note of the process id of this query.
这将显示所有正在运行的进程的列表。您可能能够找到锁定您的表的查询,因为它可能是运行时间最长的查询,还有一堆其他查询在等待锁定释放。记下此查询的进程 ID。
Then run:
然后运行:
kill [PROCESSID];
That will kill the process. Of course you need to do this as the user that has privilege to stop the query that was started (so use the same user or root
if you have to).
这将杀死该进程。当然,您需要以有权停止已启动的查询的用户身份执行此操作(因此请使用相同的用户或root
如果必须)。
回答by Puggan Se
Use a MySQL console or some other tool to run the query SHOW PROCESSLIST
to see the active query.
使用 MySQL 控制台或其他一些工具运行查询SHOW PROCESSLIST
以查看活动查询。
And the run the query kill 123
to kill a query/connection with id 123.
并运行查询kill 123
以终止 ID 为 123 的查询/连接。
回答by Tony-Caffe
Use this command to be more human readable:
使用此命令更易读:
mysql> show processlist\G
Then as some of the above said, use the command:
然后正如上面所说的,使用命令:
kill PROCESSID;
Example would be:
示例是:
kill 1234;
Where 1234 was the ID that showed up as the one that was using the most resources/ time. Be careful with this though since it can cause data corruption.
其中 1234 是显示为使用最多资源/时间的 ID。不过要小心,因为它会导致数据损坏。