MySQL: Script to find Long Running Queries and Transactions

Don’t you think so that finding Long Running Queries are a very common requirement for a Database Administrator? ‘

Yes, Database Administrators are always looking for a list of Long Running Queries.

In this post, I am sharing scripts to find Long Running Queries or Transactions of MySQL Database Server.

MySQL DBA can use this script to take necessary steps against the bad and long running queries which increase the overall performance of MySQL Database Server.

In below script, I set 59 seconds internal to find long running query since last 59 seconds.
As per your requirement, you can change this value.

Here, You can also visit few related articles.

MySQL: How to Log General and Long Running Queries into Log Table

MySQL: Using SQL Query Profiler finds total execution time and CPU information of the Queries

Script without using Performance_schema:

Script using Performance_schema:

Please share your ideas and opinions about this topic with me, your contribution will add true value to this topic.
If anyone has doubts on this topic then please do let me know by leaving comments or send me an email.

If you like this post, then please share it with others.
Please follow, I will share my experience towards the success of Database Research and Development Activity.

I put up a post every day, please keep reading and learning.
Discover Yourself, Happy Blogging !
Anvesh M. Patel.

More from

Leave a Reply

Be the First to Comment!

Notify of