首页 > 技术文章 > mysql性能优化 profile

s6-b 2020-03-10 11:22 原文

--查看当前的mysql版本是否支持

show variables like 'profiling%';

 

--默认关闭,使用前需要开启
set profiling=on;

 

--运行耗时久的sql

SELECT 
DISTINCT
io.housing_id 
FROM
t_device_report_message re
LEFT JOIN t_device_io io ON re.device_id = io.device_id 
WHERE
io.housing_id is not null
View Code

 

-- 查看结果
show profiles;

 

--诊断sql 83为问题sql数字号码
show profile for query 83;

 

-- 查看详解

Status、Duration,前者表示的是PROFILE里的状态,它和PROCESSLIST的状态基本是一致的,后者是该状态的耗时。因此,我们最主要的是关注处于哪个状态耗时最久,这些状态中,哪些可以进一步优化

https://imysql.com/2015/06/10/mysql-faq-processlist-thread-states.shtml

推荐阅读