VillageSQL is a drop-in replacement for MySQL with extensions.
All examples in this guide work on VillageSQL. Install Now →
Enabling the Slow Query Log
You can enable it at runtime without restarting the server:my.cnf or my.ini:
What Gets Logged
A typical entry looks like this:| Field | What it tells you |
|---|---|
Query_time | Total execution time in seconds |
Lock_time | Time spent waiting for locks (separate from execution) |
Rows_sent | Rows returned to the client |
Rows_examined | Rows MySQL read to produce the result |
Rows_examined / Rows_sent ratio is the key signal. If MySQL examined 847,293 rows to send back 1, it’s scanning nearly the whole table to find one result. That’s the query that needs an index.
Logging Queries Without Indexes
A lower-overhead variant: log only queries that don’t use any index, regardless of execution time.log_throttle_queries_not_using_indexes to rate-limit:
Analyzing the Log with mysqldumpslow
For a busy server the slow query log grows quickly.mysqldumpslow aggregates similar queries and ranks them by total time, making it easy to find what to fix first:
N and S:
Turning Slow Queries into EXPLAIN
Once you’ve identified the expensive queries, runEXPLAIN on them to see the execution plan:
type: ALL (full table scan) and Extra: Using filesort. Both are fixable with indexes — see How MySQL Indexes Work and Reading EXPLAIN in MySQL.
Frequently Asked Questions
What should I set long_query_time to?
Start at 1 second. Once you’ve addressed the worst queries, lower it to 0.1 to catch medium-severity issues. For performance-critical applications, 0.05 or lower is common. Setting it to 0 logs every query — useful for profiling a specific operation, not for production monitoring.
Does enabling the slow query log affect performance?
Minimally. The overhead is a small amount of I/O per logged query. On a busy production server withlong_query_time = 1, only genuinely slow queries are written — the typical overhead is negligible. Logging every query (long_query_time = 0) has measurable overhead and should only be used temporarily.
Can I query the slow log from SQL instead of reading the file?
Yes. Enable theperformance_schema slow log table or use the mysql.slow_log table if you’ve configured log_output = TABLE:
Troubleshooting
| Problem | Solution |
|---|---|
| Log file isn’t being created | Check that MySQL has write permission to the log directory |
| No entries despite slow queries | Confirm slow_query_log = ON with SHOW VARIABLES LIKE 'slow_query_log' |
| Log growing too fast | Increase long_query_time or enable log_throttle_queries_not_using_indexes |
mysqldumpslow not found | It ships with MySQL — check your MySQL bin directory (which mysqldumpslow or look in /usr/bin) |

