How To Kill MySQL Process?

MySQL database may have single or more processes in order to run database-related transactions. Over time these processes may be unnecessary or stuck and consume lots of system resources like memory, and CPU. The MySQL processes can be killed in different ways. But keep in mind that killing MySQL processes may create unexpected results like data loss, and database incompatibility. But in most cases, it can be assumed as safe.

List MySQL Processes

The MySQL interactive terminal provides the SHOW PROCESSLIST command which displays the processes lists via the MySQL terminal. First, we enter the command-line interface with the mysql command like below.

$ mysql -u root -p

Now we will run the “SHOW PROCESSLIST;” like below.


Kill MySQL Process

After listing the processes the MySQL interactive shell can be used to kill the process. The KILL command is used to kill the process. The Process ID should be provided as a parameter to the KILL command. In the following example we kill the process ID 27.

KILL 27;

List Process with ps Command

The ps aux command can be used to list all running mysql processes. The grep command is used to filter only mysql processes.

$ ps aux | grep mysql

Kill Process with kill Command

After listing the mysql processes the kill command can be used to kill MySQL process with its process ID. In the following example, we provide 2345 as MySQL process ID.

$ kill 2345

Generally, the mysql is executed with root privileges and this requires providing root privileges to kill the MySQL process.

$ sudo kill 2345

Kill All MySQL Processes

Just using the killall command all MySQL processes can be killed easily. All processes those names contain the term “mysql” will be killed.

$ killall mysql

Following commands can be used to kill MySQL processes with the names of mysqld and mysqld_safe.

$ killall mysqld
$ killall mysqld_safe

Leave a Comment