Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

The MySQL database hangs, due to some queries.

How can I find the processes and kill them?

like image 279
Ashish Dadhich Avatar asked May 26 '17 01:05

Ashish Dadhich


People also ask

How do I see what processes are running in MySQL?

Type in MYSQL to get into the mysql command line. Type show processlist; in order to see current processes on the server.

How kill all MySQL process in Linux?

Just go to task manager. Then in process, search mysqld. right click on mysqld then click on stop.

What is MySQL kill query?

KILL QUERY terminates the statement the connection is currently executing, but leaves the connection itself intact.


4 Answers

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.

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 KILL command;
  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.
like image 182
Ashish Dadhich Avatar answered Oct 12 '22 21:10

Ashish Dadhich


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;
like image 20
whistling_marmot Avatar answered Oct 12 '22 21:10

whistling_marmot


You can do something like this to check if any mysql process is running or not:

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 -9 mysql
killall -9 mysqld
killall -9 mysqld_safe    
like image 25
Pritam Banerjee Avatar answered Oct 12 '22 21:10

Pritam Banerjee


On RDS:

SELECT
  concat('CALL mysql.rds_kill(',id,');')
  FROM information_schema.processlist
  ORDER BY time;
like image 36
Moshe Avatar answered Oct 12 '22 20:10

Moshe