How to Identify MySQL Slow Query


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.

Advertisements

About piyecarane

Bla bla bla about me
This entry was posted in Linux and tagged , , , , . Bookmark the permalink.

One Response to How to Identify MySQL Slow Query

  1. zshakey says:

    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.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s