Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save sumon-sarker/6e8de53a41faa192ce82bff0434f2bfc to your computer and use it in GitHub Desktop.
Save sumon-sarker/6e8de53a41faa192ce82bff0434f2bfc to your computer and use it in GitHub Desktop.

Check the Configuration for Slow Query:

show variables like '%slow%';
show variables like '%long%';

Version 5.1.6 and above:

  1. Enter the MySQL shell and run the following command:
set global slow_query_log = 'ON';
  1. Enable any other desired options. Here are some common examples:

Log details for queries expected to retrieve all rows instead of using an index:

set global log_queries_not_using_indexes = 'ON'

Set the path to the slow query log:

set global slow_query_log_file ='/var/log/mysql/slow-query.log';

Set the amount of time a query needs to run before being logged:

set global long_query_time = 0.01; (default is 10 seconds, Here 0.01= 100ms)
  1. Confirm the changes are active by entering the MySQL shell and running the following command:
show variables like '%slow%';

Versions below 5.1.6:

Edit the /etc/my.cnf file with your favorite text editor vi /etc/my.cnf

Add the following line under the “[mysqld]” section. Feel free to update the path to the log file to whatever you want:

    log-slow-queries=/var/log/mysql/slow-query.log
  1. Enable additional options as needed. Here are the same commonly used examples from above:

Set the amount of time a query needs to run before being logged:

long_query_time=20 (default is 10 seconds)`

Log details for queries expected to retrieve all rows instead of using an index:

log-queries-not-using-indexes
  1. Restart the MySQL service:
service mysqld restart
  1. Confirm the change is active by entering the MySQL shell and running the following:
show variables like '%slow%';

Update:1

According to MySQL docs, the error #1193 occurs when you use wrong code for SQLSTATE.

Message: Unknown system variable %s

And, as you can see on the same page, the SQLSTATE 99003 is not defined.

refer this link:

http://dev.mysql.com/doc/refman/5.5/en/slow-query-log.html

http://dev.mysql.com/doc/refman/5.1/en/slow-query-log.html

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment