How to Identify MySQL Slow Query
August 14, 2009
Long query on mysql often fill up your server’s CPU and RAM with a bunch of load. It can be happened because un-optimized query, dirty table, very large row, etc.
You can enable slow query log on your mysql server :
-
Edit your my.cnf config, under [mysqld] add :
log-slow-queries = /var/log/mysql-slow.log
long_query_time = 3
- Create /var/log/mysql-slow.log and chmod it :
touch /var/log/mysql-slow.log
chown mysql.root /var/log/mysql-slow.log
-
Restart MySQL Services : service mysql restart
This will make MySQL to log queries that take more than 3 seconds to execute.




October 15, 2009 at 9:55 pm
Loving the quick guides you put up here, thank you. I knew about this feature but had no idea it was so easy to setup.