Search Our Database

How to check current running SQL queries

Last updated on |

Introduction

In a multi-user database environment, it’s crucial to monitor currently running SQL queries to ensure optimal performance, detect long-running or stuck queries, and troubleshoot database issues. This is especially important on shared hosting servers, such as those using DirectAdmin or WHM/cPanel, where multiple websites rely on the same MySQL or MariaDB instance.

 

Prerequisites

Before starting, ensure the following:

  • You have root access to the server
  • You have an active MySQL database

 

Step 1

If you established SSH connection to the server as a non-root user, switch to root with :

sudo su
Note : In order to able to switch to root, ensure the non-root user is listed in visudo.

 

Step 2

Now that you have the root access, you may log in to the MySQL console with the command :

mysql -u root -p
Note : You may be prompted with password if your server is using DirectAdmin. You may retrieve your MySQL password in /usr/local/directadmin/conf/mysql.conf

 

Step 3

As you entered MySQL console, you can use this command to see currently running SQL queries

SHOW FULL PROCESSLIST;

To identified running SQL queries you may search for queries with State : Executing . You may refer to the Time column to see how long the queries have been running.

In this example, we can see that there is a query to access the database irfanmars_testdata and it has been running for 181 seconds.

Note : The command only shows the current running queries. It will not show queries that has been completed.

 

Conclusion

By following these steps, you can effectively monitor currently running SQL queries on your server, allowing you to identify slow or problematic queries, optimize performance, and maintain database health. This practice is especially useful on multi-user or shared hosting environments, such as those managed through DirectAdmin or WHM.

However, it’s important to interpret query data responsibly, as terminating or mismanaging live database processes can impact active websites or applications. Always ensure that only trusted administrators have access to query monitoring and database controls.

For additional assistance or if you encounter any issues, please contact our support team at support@ipserverone.com.