如何找到 MySQL 进程列表并杀死这些进程?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/44192418/
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
How to find MySQL process list and to kill those processes?
提问by Ashish Dadhich
The MySQL database hangs, due to some queries.
由于某些查询,MySQL 数据库挂起。
How can I find the processes and kill them?
如何找到进程并杀死它们?
回答by Ashish Dadhich
Here is the solution:
这是解决方案:
- Login to DB;
- Run a command
show full processlist;
to get the process id with status and query itself which causes the database hanging; - Select the process id and run a command
KILL <pid>;
to kill that process.
- 登录数据库;
- 运行一个命令
show full processlist;
获取进程id和状态并查询自身导致数据库挂起; - 选择进程 ID 并运行命令
KILL <pid>;
来终止该进程。
Sometimes it is not enough to kill each process manually. So, for that we've to go with some trick:
有时手动杀死每个进程是不够的。因此,为此我们必须使用一些技巧:
- Login to MySQL;
- Run a query
Select concat('KILL ',id,';') from information_schema.processlist where user='user';
to print all processes withKILL
command; - Copy the query result, paste and remove a pipe
|
sign, copy and paste all again into the query console. HIT ENTER. BooM it's done.
- 登录MySQL;
- 运行查询
Select concat('KILL ',id,';') from information_schema.processlist where user='user';
以使用KILL
命令打印所有进程; - 复制查询结果,粘贴并删除管道
|
标志,再次复制并粘贴到查询控制台中。按回车键。轰它完成了。
回答by whistling_marmot
select GROUP_CONCAT(stat SEPARATOR ' ') from (select concat('KILL ',id,';') as stat from information_schema.processlist) as stats;
Then copy and paste the result back into the terminal. Something like:
然后将结果复制并粘贴回终端。就像是:
KILL 2871; KILL 2879; KILL 2874; KILL 2872; KILL 2866;
回答by Pritam Banerjee
You can do something like this to check if any mysql
process is running or not:
您可以执行以下操作来检查是否有任何mysql
进程正在运行:
ps aux | grep mysqld
ps aux | grep mysql
Then if it is running you can killall
by using(depending on what all processes are running currently):
然后,如果它正在运行,您可以killall
使用(取决于当前正在运行的所有进程):
killall -9 mysql
killall -9 mysqld
killall -9 mysqld_safe