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

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.