Main menu:

Site search

Categories

Archive

Logging long running queries in mysql

Here is another nugget from the mysql world.

Mysql has a built in logger for tracking down those queries that are long running queries. Technically mysql likes to call them “slow queries”

1. Login to your server as root

2. Open my.cnf with your favorite editor. Example:

3. Into the [mysqld] section add the fallowing lines

log-slow-queries = /var/log/mysql-slow.log
long_query_time = 3

4. Go ahead and save the configuration.

5. Now we have to actually create the log file.

touch /var/log/mysql-slow.log

6. Now we are changing the owner of the file so that mysql and actually write to it.

chown mysql.root /var/log/mysql-slow.log

7. Now we restart mysql

service mysql restart

TADA you got a log with all the long running queries in it that are running longer than 3 seconds.

do a tail -f /var/log/mysql-slow.log and watch your log grow.

Write a comment