First, Introduction to open the slow query log, you can let the MySQL record query over a specified time of the statement, through the location analysis performance bottlenecks, to better optimize the performance of the database system
Second, parameter description slow_query_log slow query on the status slow_query_log_file slow query log location (this directory requires the MySQL running account of the writable permissions, generally set to the MySQL data storage directory) Long_query_ Time query more than how many seconds to log
third, set the steps 1. View slow Query related parameters
Mysql> Show variables like'slow_query%';+---------------------------+----------------------------------+| variable_name | Value |+---------------------------+----------------------------------+| Slow_query_log | OFF | | Slow_query_log_file | /mysql/data/localhost-slow.log |+---------------------------+----------------------------------+MySQL> Show variables like'Long_query_time';+-----------------+-----------+| variable_name | Value |+-----------------+-----------+| Long_query_time |10.000000|+-----------------+-----------+
2 . Set method Method One: Global variable setting sets the Slow_query_log global variable to the "on" State
Set Global slow_query_log='on'
Set the location where the slow query log is stored
Set Global slow_query_log_file='/usr/local/mysql/data/cbx-slow.log';
The query is logged in more than 10 seconds
Set Global long_query_time=;
Method Two: Configuration file settings
==/usr/local/mysql/data/1
3 . Restart MySQL service mysqld restart
4. View the parameters after setting
mysql> Show variables like " slow_query% " ; +---------------------+--------------------------------+| variable_name | Value |+---------------------+--------------------------------+| Slow_query_log | On | | Slow_query_log_file | /usr/local/mysql/data/slow.log |+---------------------+--------------------------------+ mysql > show variables like " long_query_time " +-----------------+----------+| variable_name | Value |+-----------------+----------+| Long_query_time | 1.000000 |+-----------------+----------+
Iv. Testing 1 . Execute a slow query SQL statement MySQL Select Sleep (n); 2 . See if a slow query log is generated 3. ls/usr/local/mysql/data/cbx-slow.log4. If the log is present, MySQL turns on slow query settings successfully!
mysql-Slow Query log