mysql slow query record

Question of the day: How to enable slow query in mysql?

This answer is for reference only:

1. Parameter description

slow_query_log Slow query on state
slow_query_log_file The location where the slow query log is stored (this directory needs the writable permission of the MySQL running account, and is generally set to the MySQL data storage directory)
long_query_time How many seconds to record the query

View slow query related parameters
mysql> show variables like'slow_query%';
mysql> show variables like'long_query_time ';

2. Setting method

Method 1: Global Variable Setting

Set the slow_query_log global variable to "ON" state
mysql> set global slow_query_log='ON';

Set the location of slow query log storage
mysql> set global slow_query_log_file='/usr/local/mysql/data/slow.log';

If the query exceeds 1 second, record
mysql> set global long_query_time=1;

Method two: configuration file settings

Modify the configuration file my.cnf and add
[mysqld]
slow_query_log = ON
slow_query_log_file = /usr/local/mysql/data/slow.log
long_query_time = 1 under [mysqld]

3. Restart the MySQL service
service mysqld restart

4. View the parameters after setting
mysql> show variables like'slow_query%';
mysql> show variables like'long_query_time ';

Guess you like

Origin blog.csdn.net/steven27_3/article/details/107355415
Recommended