The mysql version is mysql5.6.22, and the installation environment is windows7.
1. Using this query log, you can find the sql statement of the efficiency problem, record it, and monitor it.
You can use the following statement to query and set the slow query log
(1) Check whether the slow query log is enabled with
SHOW VARIABLES LIKE '%show_query_log%';
Or SHOW VARIABLES LIKE '%show_query_log%'\G (used in the mysql command line) The
query result is as follows
Variable_name: slow_query_log
Value: OFF The
value above means that
Variable_name: slow_query_log_file
Value: D:\ProgramFiles\MySQL5.6.22\mysql_master\data \LHY-slow.log
The value above indicates the path where the log is stored
Set the on state: set global slow_query_log = on;
(2) Check whether SHOW VARIABLES LIKE '%log_queries_not_using_indexes%' is enabled for query logs that do not use indexes ;
Or SHOW VARIABLES LIKE '%log_queries_not_using_indexes%'\G (used in the mysql command line) The
query result is as follows
Variable_name: log_queries_not_using_indexes
Value: OFF
The value above indicates that it is not turned on
Set the open state: set global log_queries_not_using_indexes = on;
(3) View the query log that exceeds the set time
SHOW VARIABLES LIKE '%long_query_time%';
Or SHOW VARIABLES LIKE '%long_query_time%'\G (used in the mysql command line) The
query result is as follows:
Variable_name: long_query_time
Value: 10.000000
The above value: 10s means that the sql that records the execution time of more than 10 seconds
Set the execution time to 1s
set global long_query_time = 1;
exit;
Note 1: It will only work if you log out and log in again after the modification is executed.
Note 2: If the setting time is too short, too many log records will quickly fill up the disk space, so disk cleanup should be performed regularly. The setting here is 1 In order to check the execution effect, you need to set it yourself in the production environment.
After the above three steps are completed, any sql statement executed from the database will be recorded in the log. You can go to the log in the first step to view the log information. The
above settings are In the console processing, when the database is restarted, the setting will be invalid;
the long-term effective way is to find the my.ini file in the mysql installation directory. If there is no such file, only the mysql-default.ini file
will be backed up. , and then renamed mysql.ini, and then add the following configuration information under [mysqld] in the file.
slow_query_log=on
slow_query_log_file=D:/ProgramFiles/MySQL5.6.22/mysql_master/data/LHY-slow.log
log_queries_not_using_indexes=on
long_query_time=1
2. Storage format
# Time: 150401 11:24:27
# User@Host: root[root] @ localhost [127.0.0.1] Id: 7
# Query_time: 0.034002 Lock_time: 0.000000 Rows_sent: 3 Rows_examined: 3
use libu;
SET timestamp=1427858667;
select * from aaa;
The analysis is as follows:
(1) Time: execution time
(2) User@Host: host information for executing sql
(3) Query_time: sql execution information, Lock_time: lock time, Rows_sent: number of rows sent (results), Rows_examined: number of rows scanned
(4) timestamp: execution time
(5) select * from aaa; : query content
3. Slow query log analysis tool
5种工具: mysqldumpslow,mysqlsla,myprofi,mysql-explain-slow-log,mysqllogfilter
mysqldumpslow mysql's own analysis tool
The source of this article is http://www.2cto.com/database/201504/387155.html