美文网首页
mysql 性能分析(show profile)

mysql 性能分析(show profile)

作者: 多彩海洋 | 来源:发表于2019-06-23 21:02 被阅读0次

1 MySQL性能分析语句show profile

1.1 介绍

l Query Profiler是MYSQL自带的一种query诊断分析工具,通过它可以分析出一条SQL语句的性能瓶颈在什么地方。

l 通常我们是使用的explain(关注 参数 有 type key,ref,rows),以及slow query log都无法做到精确分析,但是Query Profiler却可以定位出一条SQL语句执行的各种资源消耗情况,比如CPU,IO等,以及该SQL执行所耗费的时间等。不过该工具只有在MYSQL 5.0.37以及以上版本中才有实现。

l 默认的情况下,MYSQL的该功能没有打开,需要自己手动启动

1.2 语句使用

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

l show profiles :以列表形式显示最近发送到服务器上执行的语句的资源使用情况.显示的记录数由变量:profiling_history_size 控制,默认15条

image.png

l show profile: 展示最近一条语句执行的详细资源占用信息,默认显示 Status和Duration两列

image.png

l show profile 还可根据 show profiles 列表中的 Query_ID ,选择显示某条记录的性能分析信息

image.png

1.3 开启Profile功能

l Profile 功能由MySQL会话变量 : profiling控制,默认是OFF关闭状态。

l 查看是否开启了Profile功能:

** select @@profiling;**

show variables like ‘%profil%’;

image.png

l 开启profile功能

  • set profiling=1; --1是开启、0是关闭

1.4 示例

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

select @@profiling;

image.png
  1. 打开 profiling 功能

set profiling=1;

image.png
  1. 执行sql语句
image.png
  1. 执行 show profiles 查看分析列表
image.png

5.可指定资源类型查询

show  profile cpu ,swaps for query 1;

相关文章

网友评论

      本文标题:mysql 性能分析(show profile)

      本文链接:https://www.haomeiwen.com/subject/mxvwqctx.html