查看慢SQL 配置
1
show VARIABLES like '%query%'
查看日志保存形式
1
show VARIABLES like '%log_output%'
设置文件和表保存
1
set global log_output='FILE,TABLE';
设置5秒
1
set global long_query_time=5.000000
测试慢SQL
1
select sleep(6)
查询慢SQL结果
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
select * from mysql.slow_log;
# 或
SELECT
start_time '执行时间',
rows_sent '返回结果行数',
rows_examined '扫描行数',
query_time '执行耗时',
db '所属数据库',
user_host '执行者信息',
IF(db='process_engine_v1_sit','朱振兴',IF(db='itmp_backend_db','沈宏俊','其他'))'跟进人',
CONVERT(sql_text USING utf8) '执行SQL'
FROM
mysql.slow_log t
WHERE
start_time > '2022-07-05 00:00:00.000000'
AND query_time > '00:00:04.000000'
ORDER BY
query_time DESC