How can I view mysql slow_query_log to see which query is taking too much time?
A:
Check the location of this log in my.ini file, and then open it in any text editor.
Mchl
2010-10-26 07:48:37
+1
A:
First, you need to check if it's enabled in your MySQL configuration (mysql.ini or mysql.cnf, depending on your system):
# enable slow log:
slow_query_log = 1
# log queries longer than n seconds:
long_query_time = 5
# where to log:
slow_query_log_file = /path/to/your/logs/mysql-slow.log
Restart your MySQL server, then watch the logfile using whatever program you like - tail
is the simplest:
tail -f /path/to/your/logs/mysql-slow.log
You may need to play a bit with the long_query_time
setting to find the limit where the volume of logging isn't too low or too high, but just right.
Piskvor
2010-10-26 07:49:56
my slow_query_log_file is "/var/log/mysql-slow-log".
BhatiaVJ
2010-10-26 08:48:42
@BhatiaVJ: That's possible, yes - that's why I added the instructions to get its location from config, as each distro may have the file in a slightly different location by default, plus the path is obviously configurable.
Piskvor
2010-10-26 09:37:40