tags:

views:

34

answers:

3
+1  Q: 

MYSQL Slow Query

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
A: 

if you ask google for "slow_query_log", this is the first hit - explaining all you need to know. you have to enable it, set a filename you like (if it's already set, you can find the configuration in you my.ini), start your queries and look ito that file...

oezi
+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
my slow_query_log_file is "/var/log/mysql-slow-log".
BhatiaVJ
@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