? linux 系统mysql默认配置文件路径 /etc/my.cn
vi /etc/my.cnf
? 打开my.cn配置文件如下图:?
慢日记配置项说明:
slow_query_log=1? ? ? ?表示开启记录执行慢的sql日记
slow-query-log-file=/www/server/data/mysql-slow.log? ? ? ?慢的sql日记保存的位置
long_query_time=3? 执行的sql时间超过3秒则记录
? 执行 sql查看慢日记如下:
SHOW VARIABLES LIKE 'slow_query_log%';
? 执行后如下图:?
?
用vi 打开开慢日记文件
vi /www/server/data/mysql-slow.log
? 找到问题sql,如下:
SELECT * FROM (
SELECT ADDDATE('1970-01-01',t5.i*100000+t4.i*10000+t3.i*1000+t2.i*100+t1.i+10+t0.i) select_date
FROM
(SELECT 0 i UNION SELECT 1 UNION SELECT 2 UNION SELECT 3 UNION SELECT 4 UNION SELECT 5 UNION SELECT 6 UNION SELECT 7 UNION SELECT 8 UNION SELECT 9) t0,
(SELECT 0 i UNION SELECT 1 UNION SELECT 2 UNION SELECT 3 UNION SELECT 4 UNION SELECT 5 UNION SELECT 6 UNION SELECT 7 UNION SELECT 8 UNION SELECT 9) t1,
(SELECT 0 i UNION SELECT 1 UNION SELECT 2 UNION SELECT 3 UNION SELECT 4 UNION SELECT 5 UNION SELECT 6 UNION SELECT 7 UNION SELECT 8 UNION SELECT 9) t2,
(SELECT 0 i UNION SELECT 1 UNION SELECT 2 UNION SELECT 3 UNION SELECT 4 UNION SELECT 5 UNION SELECT 6 UNION SELECT 7 UNION SELECT 8 UNION SELECT 9) t3,
(SELECT 0 i UNION SELECT 1 UNION SELECT 2 UNION SELECT 3 UNION SELECT 4 UNION SELECT 5 UNION SELECT 6 UNION SELECT 7 UNION SELECT 8 UNION SELECT 9) t4,
(SELECT 0 i UNION SELECT 1 UNION SELECT 2 UNION SELECT 3 UNION SELECT 4 UNION SELECT 5 UNION SELECT 6 UNION SELECT 7 UNION SELECT 8 UNION SELECT 9) t5
) a;
执行上面问题sql后,发现是生成日期?1970-01-11 至?4707-09-18 ,哎
?很显示有问题,什么业务时间需要这么长4707-09-18,如果真的需要也不用每次生成,保存一张表去查不是更快。