Databases 5 min read

Master MySQL Slow Query Log: Enable, Analyze, and Choose the Best Tools

This guide explains how to enable MySQL's slow query log, configure it in my.cnf, and compares five popular analysis tools—mysqldumpslow, mysqlsla, mysql-explain-slow-log, mysql-log-filter, and myprofi—detailing their features, output formats, and advantages to help you select the most suitable solution.

MaGe Linux Operations
MaGe Linux Operations
MaGe Linux Operations
Master MySQL Slow Query Log: Enable, Analyze, and Choose the Best Tools

Enable Slow Query Log

MySQL's slow log records queries that exceed the long_query_time threshold. To enable it, add the following lines to my.cnf and restart the MySQL service:

[mysqld]
slow_query_log=on
slow_query_log_file=mysql-slow

Toolset

Five commonly used tools for analyzing the slow query log:

mysqldumpslow – the official MySQL tool that provides basic statistics and generates charts.

mysqldumpslow output chart
mysqldumpslow output chart

mysqlsla – a powerful Perl script from hackmysql.com offering detailed reports such as query count, execution time, lock time, rows sent, rows examined, database, user, and abstracted SQL.

mysqlsla report
mysqlsla report

mysql-explain-slow-log – a Perl script written by a German author; it prints the entire slow log and only provides count statistics, making it less recommended.

mysql-explain-slow-log example
mysql-explain-slow-log example

mysql-log-filter – Python or PHP scripts found on Google Code; adds average, max, and cumulative query time statistics and formats the output for readability.

mysql-log-filter output
mysql-log-filter output

myprofi – an open‑source PHP tool (SourceForge) that provides a very concise report focusing on total slow query count, distinct SQL statements, execution frequency, and percentage of total slow log entries.

myprofi output
myprofi output

Summary Comparison

mysqldumpslow – basic statistics, Perl, built‑in MySQL tool.

mysqlsla – supports both basic and advanced statistics, Perl, powerful and customizable reports.

mysql-explain-slow-log – only basic statistics, Perl, limited functionality.

mysql-log-filter – basic and partial advanced statistics, Python/PHP, clean formatted output.

myprofi – basic statistics, PHP, extremely concise.

Additional Recommendation

For deeper query analysis, consider pt-query-digest from Percona Toolkit.

Official site: http://www.percona.com/doc/percona-toolkit/2.2/pt-query-digest.html

MySQLPerformance AnalysisDatabase ToolsSlow Query Logmysqldumpslowmysqlsla
MaGe Linux Operations
Written by

MaGe Linux Operations

Founded in 2009, MaGe Education is a top Chinese high‑end IT training brand. Its graduates earn 12K+ RMB salaries, and the school has trained tens of thousands of students. It offers high‑pay courses in Linux cloud operations, Python full‑stack, automation, data analysis, AI, and Go high‑concurrency architecture. Thanks to quality courses and a solid reputation, it has talent partnerships with numerous internet firms.

0 followers
Reader feedback

How this landed with the community

Sign in to like

Rate this article

Was this worth your time?

Sign in to rate
Discussion

0 Comments

Thoughtful readers leave field notes, pushback, and hard-won operational detail here.