如何找到 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

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-31 22:20:45  来源:igfitidea点击:

How to find MySQL process list and to kill those processes?

mysqlkill-process

提问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:

这是解决方案:

  1. Login to DB;
  2. Run a command show full processlist;to get the process id with status and query itself which causes the database hanging;
  3. Select the process id and run a command KILL <pid>;to kill that process.
  1. 登录数据库;
  2. 运行一个命令show full processlist;获取进程id和状态并查询自身导致数据库挂起;
  3. 选择进程 ID 并运行命令KILL <pid>;来终止该进程。

Sometimes it is not enough to kill each process manually. So, for that we've to go with some trick:

有时手动杀死每个进程是不够的。因此,为此我们必须使用一些技巧:

  1. Login to MySQL;
  2. Run a query Select concat('KILL ',id,';') from information_schema.processlist where user='user';to print all processes with KILLcommand;
  3. 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.
  1. 登录MySQL;
  2. 运行查询Select concat('KILL ',id,';') from information_schema.processlist where user='user';以使用KILL命令打印所有进程;
  3. 复制查询结果,粘贴并删除管道|标志,再次复制并粘贴到查询控制台中。按回车键。轰它完成了

回答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 mysqlprocess is running or not:

您可以执行以下操作来检查是否有任何mysql进程正在运行:

ps aux | grep mysqld
ps aux | grep mysql

Then if it is running you can killallby using(depending on what all processes are running currently):

然后,如果它正在运行,您可以killall使用(取决于当前正在运行的所有进程):

killall -9 mysql
killall -9 mysqld
killall -9 mysqld_safe