MySQL MariaDB

How to Get List of Running Queries in MySQL Processlist?

While working with a MySQL database, occasionally users need to view the running queries in the processlist of the MySQL server. These results can aid the user to do many important tasks including performance monitoring, troubleshooting, resource management, query analysis, and capacity planning. There are different ways to get the list of running queries in MySQL.

This post will help you to learn how to get a list of running queries in MySQL processlist.

How to Get a List of Running Queries in MySQL processlist?

In MySQL, there is a database named “information_schema” that contains metadata about the MySQL server including the “processlist” table. This processlist contains information about each running query, including the query ID, user, host, database, command, execution time, state, and additional information. However, MySQL offers different methods to view the running queries. Let’s head toward these methods.

Method 1: Using information_schema.processlist

To view the details of running queries, execute the command given below:

SELECT * FROM information_schema.processlist;

The command will select all columns of the processlist table.

Output

The output displayed detailed information about each running query.

Method 2: Filtering Sleeping Queries

If a user is only interested in the active queries, then the following command can be used:

SELECT * FROM information_schema.processlist WHERE COMMAND != 'Sleep';

The above command uses the “where” clause to filter out the queries that are not in the sleep state.

Output

The output provided the list of active queries.

Method 3: Using SHOW PROCESSLIST Command

To display the currently running queries by utilizing the “PROCESSLIST” execute the given below command:

SHOW PROCESSLIST;

This command will return the information of running queries in tabular form.

Output

Here in the above output, the detailed information of the running query can be observed.

Method 4: Obtain Detailed Processlist

MySQL also enables its users to obtain the more detailed value of running queries by including additional information such as the SQL statement being executed. To do so, run the given command:

SHOW FULL PROCESSLIST\G

The command uses the “\G” modifier to format the output vertically.

Output

Here you can see the output returned with detailed information about running queries.

Method 5: Using mysqladmin Command-Line Utility

The user can also utilize the “mysqladmin” utility to get the information of running queries on the MySQL server by executing the given command:

mysqladmin -u md -p processlist

The command contains MySQL server username “md” in it. Make sure to change the username according to your MySQL server.

Output

The output displays the information about running queries in the processlist:

That’s all about getting the list of running queries in MySQL processlist.

Conclusion

In MySQL, various commands are used to get the list of running queries, such as “SHOW PROCESSLIST”, “SHOW FULL PROCESSLIST\G”, etc. It helps the users to perform important tasks such as troubleshooting, resource management, and query analysis. The user can utilize different commands to get the list of running queries in MySQL processlist. Moreover, the mysqladmin utility can also be used for providing the details of running queries of MySQL server.

About the author

Danish Ghafoor

I am a computer science graduate with a certification in cybersecurity. My passion for technology has led me to develop a deep understanding of the challenges and solutions in the field of information security. I am dedicated to staying up-to-date with the latest industry trends and technologies, and constantly seeking out new opportunities to expand my knowledge and skills.