How to kill a MySQL process?


How do I find which mysql process has crashed, or is stuck and not running to completion, and then how to KILL it?

FYI, if via mytop I see that process ID 2987 has been running for 78000
seconds, I am assuming that this process has crashed. Then how to kill it?


I don’t know if this will help, but in my localhost XAMPP, the xampp_stop.exe file runs the mysql_stop.bat file which is

@echo off
echo Mysql shutdowm ...
mysql\\bin\\mysqladmin --user=pma --password= shutdown

What operating system?


I do not want to Stop MySQL, but just to find what MySQL processes have crashed and KILL it specifically.



The operating system is Linux, Red Hat Enterprise.
Web server is Apache.


Maybe something like this (or the class) from

$result = mysql_query("SHOW FULL PROCESSLIST");
while ($row=mysql_fetch_array($result)) {
if ($row["Time"] > 200 ) {
$sql="KILL $process_id";


Thanks for this code.
Actually this is a very useful/good PHP code.

But I am just looking for the exact MySQL or Linux command to do this
job from either the MySQL client or the Linux command line.


kill connection process_id


Bu my question was how do I find out which MySQL process_id to kill
without logging into MySQL, but just being logged into the server via SSH.

how do you check your regular processes that are running and know which ones have crashed? if you run your

ps -l

that will give you your process list, but IIRK it doesn’t suggest which is a crashed process and which isn’t does it? sorry but been a while since i’ve worked on unix/linux box.

You might try

ps -waux

what you’re actually looking for is the SHOW PROCESS LIST and KILL commands.

you definitely don’t want to issue an OS level kill command against mysql, especially if that connection is making changes.

mysql -h <hostname> -u <username> -p <database_name>
KILL ###;

After the first command you will be prompted to enter your password
After the second command you should note the process id and use that in the third command.