###第十一部分:MySQL慢SQL查询
#开启
SET GLOBAL slow_query_log=ON;
#慢SQL执行时间阈值,单位(秒) ,1毫秒=0.001
#不建议超过300ms,最终结果视情况而定
SET GLOBAL long_query_time=0.3;
#指定慢SQL文件名为slow-sql,慢SQL日志保存在mysql/data目录下
SET GLOBAL slow_query_log_file="slow-sql.log";
#是否记录没有使用索引的SQL语句
SET GLOBAL log_queries_not_using_indexes=ON;
#my.cnf
SHOW VARIABLES LIKE '%query%';
###慢查询
EXPLAIN
SELECT F.*, E.courseName
FROM exam_student_subjective_fileurl_51_2019_10 F,exam_paper E
WHERE F.examPaperId = E.examPaperId AND F.examId = E.examId AND E.examId <> 458;
# Time: 2019-05-14T07:07:36.814164Z - 执行时间
# User@Host: root[root] @ localhost [::1] Id: 29 - 环境信息
# Query_time: 0.020783 - 查询时间 *****
# Lock_time: 0.000105 - 资源锁定时间
# Rows_sent: 9539 - 查询结果总行数
# Rows_examined: 19078 - 扫描的行数 *****
#SET timestamp=1557817656; - 时间戳
#=======SQL==========
#select gc.*, g.title from t_goods g , t_goods_cover gc
#where g.goods_id = gc.goods_id and g.goods_id > 60;