A popular relational database management system for web development and other uses is MySQL. Occasionally, MySQL processes need to be managed to improve system performance, solve problems, or end rogue processes. Both database administrators and developers must be able to locate and terminate MySQL processes quickly.

This tutorial will cover how to find and kill MySQL processes so that database performance and operation run smoothly. MySQL processes that are not required can slow down your system. As a server accumulates too many open threads, it becomes unresponsive, making it impossible for users to view tables or submit requests.

Required Conditions

  • User with root or sudo rights
  • Having access to a terminal or command line
  • Installed MariaDB or MySQL

Guide to Find The List of MySQL Processes

You need to access a local or distant MySQL server before you can find and terminate a process. Use the terminal to open your MySQL local account and log in as root by entering:

mysql -u root -p

When asked, enter the password. Mysql> appears at the prompt when the MySQL shell loads.

Load the list with all of the active sessions to find the process you want to terminate or kill.
Enter this query into the MySQL shell:


The following information is shown in the output:

mysql show processlist

Your list might have more entries than usual. Make a note of the process’s ID before terminating it. The processes that are running the longest can be found using the Time column. Generally speaking, you want to fire those first.

Methods for Terminating the MySQL Process

Use the KILL query and the thread ID you previously noted to end a MySQL session from the list.

KILL 14;

The query status and the number of rows impacted are shown by the shell: “Query OK, 0 rows affected (0.06 sec).” With this query, the connection to the database is closed, along with all related activities.

Keep in mind that the ability to terminate a process requires the right kind of rights.

How to End Every MySQL Process for a Particular User

There isn’t a special command in MySQL for ending all processes. Use CONCAT to create a file containing the list of threads and statements if you want to terminate all processes for a particular user. We entered root as the user in our instance. Replace the root with the desired username to indicate a different user.

SELECT CONCAT('KILL ',id,';') FROM information_schema.processlist WHERE user='root' INTO OUTFILE '/tmp/process_list.txt';

The process_list.txt file was produced by this query. The name can be changed to your preference. If those are the processes you wish to terminate, open the file and check. When you’re prepared, type in:

SOURCE /tmp/process_list.txt;

To make the list of processes in the result file more manageable, you can include criteria in the query. For instance, to include only the processes with a time value greater than 1000, add time > 1000 to the command.

SELECT CONCAT('KILL ',id,';') FROM information_schema.processlist WHERE user='root' and time>1000 INTO OUTFILE '/tmp/process_list.txt';

Final Words on How to Find and Terminate / Kill MySQL Process

To sum up, knowing how to locate and end MySQL processes is essential to keeping a reliable and effective database system. Database administrators and developers may efficiently manage MySQL processes, diagnose issues, and enhance system performance by employing the tools and instructions covered in this article. Possessing a thorough understanding of MySQL process management enables users to monitor and manage resource-intensive queries as well as discover and terminate inactive connections, thereby preserving the stability and overall health of their database systems.

MySQL settings are capable of functioning smoothly and guaranteeing the dependable storage and retrieval of data for a range of users and applications with cautious oversight and prudent use of termination commands. We have described here the simplest method for locating and terminating MySQL processes. Before executing a MySQL query, always confirm which processes you are ending.