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

This Comment will be submitted for moderation and will not be accessible to other users until it has been approved.


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 Comment

  • 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 <% ... %>.