MySQL性能分析语句 show profile/show profiles

功能说明

  • show profile 和 show profiles 语句可以展示当前会话(退出session后,profiling重置为0) 中执行语句的资源使用情况.

例一、

1、查看是否打开了性能分析功能

select @@profiling;
MySQL性能分析语句 show profile/show profiles


2、打开 profiling 功能

set profiling=1;
MySQL性能分析语句 show profile/show profiles

3、执行sql语句 

MySQL性能分析语句 show profile/show profiles

4、执行 show profiles 查看分析列表 

MySQL性能分析语句 show profile/show profiles

5、查询第二条语句的执行情况

show profile for query 2;
MySQL性能分析语句 show profile/show profiles


6、可指定资源类型查询

show profile cpu,swaps for query 2; 

MySQL性能分析语句 show profile/show profiles

例二、

不用索引的,虽然检索的行数多,但是直接访问表数据快

时间差一个单位

MySQL性能分析语句 show profile/show profiles