slow query log in MySQL

Mysql slow query log

How to enable the slow query log in MySQL

Step by step process for enabling mysql slow query log

Step 1: First we need to open mysql config file in my case mysql config file location is /etc/my.cnf

Note: mysql config file location may be differnt in yor case

Step 2: Add below line in my.cnf file under the “[mysqld]” section

Then Save and Exit mysql config file (Esc :wq!) Now we used long_query_time=5 it is if any query taking more then 5 seconds to execute then the query will be saved in slow query log file.In your case you may used different path for log file.

Step 3: creating mysql folder and slow-query.log in /var/log/ and setting ownership

Step 4: Then we need to restart the MySQL service:

Step 5: Confirm the changes for that enter in mysql shell mysql -uroot -ppassword databasename

Here we can check log_slow_queries is ON

Step 6: Start monitoring file for this you may open the file in vi editor or use taill command to check

this line will display last 500 line of /var/log/mysql/slow-query.log Here we completed slow query log in MySQL


You May Also Enjoy Reading This …

Leave a Reply

Your email address will not be published. Required fields are marked *