Enable Slow Query logs in Mysql

Enable Slow Query logs in Mysql

Enable Slow Query logs in Mysql

 

We can enable mysql slow query log by two way:

  1. Step 1

 

# touch /var/log/mysql/mysql-slow.log

# chown mysql:mysql /var/log/mysql/mysql-slow.log

# mysql -u username -ppassword -e ‘SET GLOBAL slow_query_log=1;’

# mysql -u username -ppassword -e ‘SET GLOBALslow_query_log_file=”/var/log/mysql/mysql-slow.log”;’

# mysql -u root -ppassword -e ‘SET GLOBAL long_query_time=2;’

MySql_slow_qurry _log_html_m78fddf01

Above can be done without restarting Mysql service.

 

To keep slow query logging onĀ  add below three lines in mysql configuration my.cnf file.

 

# Vi /etc/my.cnf

slow_query_log=1
slow_query_log_file=/var/log/mysql/mysql-slow.log
long_query_time=2

 

MySql_slow_qurry _log_html_1c8b2133

To reflect changes need to restart Mysql service.

 

# /etc/init.d/mysqld restart

Leave a comment

Your email address will not be published.


*