slow SQL Log query ：
Check whether to turn on slow query log ：
show variables like '%slow%';
linux Open under my.cnf Of [mysqld] Add the following ：
Open slow query log . modify MySQL Configuration file for my.cn Usually in /etc Below directory , Add the following three lines to configure and restart MySQL.
slow_query_log = ON slow_launch_time = 2 slow_query_log_file = /usr/local/mysql/data/slow_query.log
low_launch_time It's only accurate to seconds , If you need more accuracy, you can use some third-party tools, such as those described later pt-query-digest.
Be careful ： I used it here MySQL The version is 5.6, Different versions MySQL The configuration of enabling slow query is different , such as 5.6 Some previous versions were ong_query_time, long_query_time and log-slow-queries.
You can execute... At the terminal first show variables like '%slow%'; Check the specific configuration of the current version .
You can also open the slow query log by setting the global variable at the terminal ：↓
set @@global.slow_query_log = ON;
Save slow query log to table ：
MySQL Support saving slow query logs to mysql.slow_log In this list . adopt @@global.log_output You can set the default to TABLE,FILE and TABLE Only one... Can be used at the same time .
We can use the following statement to simulate a slow query ：
a citation ：https://blog.csdn.net/wulantian/article/details/40296541