How to find out slow queries in MYSQL to enhance and optimize them for peformance

Submitted by geekyguy on Tue, 06/26/2007 - 05:14.
::

Step by Step solution:

1. Go to /etc/rc.d/init.d/mysqld

2. Locate line: /usr/bin/mysqld_safe --defaults-file=/etc/my.cnf

3. Add option: --log-slow-queries="/var/log/slow-queries.log" to this line. Now the line becomes: /usr/bin/mysqld_safe --defaults-file=/etc/my.cnf --log-slow-queries="/var/log/slow-queries.log"

4. Create an empty file: touch /var/log/slow-queries.log

5. Give permission: chmod 644 /var/log/slow-queries.log

6. Restart mysql

mysqld will log all slow queries to this file.

Post your Answer

  • Lines and paragraphs break automatically.
  • You can enable syntax highlighting of source code with the following tags: <code>, <blockcode>, <c>, <cpp>, <drupal5>, <drupal6>, <java>, <javascript>, <php>, <python>, <ruby>. Beside the tag style "<foo>" it is also possible to use "[foo]". PHP source code can also be enclosed in <?php ... ?> or <% ... %>.
  • Links to specified hosts will have a rel="nofollow" added to them.

More information about formatting options