MySQL中profiling的使用

MySQL5.0之后便开始支持profiling,用于诊断一条sql在执行过程中的资源消耗情况,可以通过profiling来查看慢sql到底慢在哪里,从而进行合理的优化

  1. 查看profiling是否支持和开启
show variables like '%profil%'
Variable_name Value
have_profiling(是否支持profiling) YES
profiling(是否开启profiling) ON
profiling_history_size(profiling每次展示的行数) 15
  1. 如果上面profiling的值为0或者OFF,那么开启profile
set profiling=1
  1. 开始使用profiling
# 执行一条sql
select count(*) from vc
# 使用profiling
SHOW PROFILES

SHOW PROFILES的执行结果
Query_ID:查询的ID
Duration:执行的耗时
Query:执行的具体sql
可以在结果中找到我们刚才执行的那条sql

# 通过Query_ID查看sql具体的执行情况
# 也可以通过Show profile all for query 174查询更多的信息
Show profile for query 174

在这里插入图片描述

Status:表示执行这条sql所经历的阶段
Duration:每个阶段的耗时

猜你喜欢

转载自blog.csdn.net/progammer10086/article/details/106526045
今日推荐