开启show profile 查看sql执行周期

修改配置文件 /etc/my.cnf
新增一行: query_cache_type = 1;
重启mysql
先开启,然后看看 show variables like ‘%profiling%’;
set profiliing = 1;
执行一些sql语句
show profiles ;显示最近几次查询

Show Profile - 图1

1 是否支持,看看当前mysql 版本是否支持

2 开启功能,默认是关闭,使用前需要开启

  1. show variables like 'profiling';

4 show profiles

Show Profile - 图2

5诊断sql 输入 show profile cpu,block io for query 3 其中3是id ,结合上图查看

Show Profile - 图3

其中 show profile 的语句 type 包括 以下几种

Show Profile - 图4

Show Profile - 图5
出现这4种都是很头疼的事情,出现这4个其中一种,则必须优化