Skip to main content

Log slow query - MySQL

Ref: The Slow Query Log

Set in config

[mysqld]
slow-query-log=ON
log_output={ FILE | TABLE }

# Log file
# Default = <data directory>/<host name>-slow.log
slow_query_log_file=<file>

# Log query longer than <seconds>
# Default = 10
long_query_time=<seconds>

# Log query not using index
# Default = OFF
log-queries-not-using-indexes=ON

Set on runtime

set global slow_query_log = 'ON';

Display slow query status

show global variables like 'slow_query%';
+---------------------+-------------------------------------+
| Variable_name | Value |
+---------------------+-------------------------------------+
| slow_query_log | ON |
| slow_query_log_file | /var/lib/mysql/<host name>-slow.log |
+---------------------+-------------------------------------+
2 rows in set (0.00 sec)