在正式学习前需要测试当前的 MySQL 版本是否支持 profile
,具体命令如下所示:
select @@have_profiling

使用该命令可以获取一个查询在整个执行过程中各个资源消耗情况,例如 CPU,IO,SWAP……
如果支持还需要查看一下 profile
是否开启,命令如下:
select @@profiling

如果没有开启,可以通过 set profiling = 1
开启该配置。
接下来建造一张百万数据的表,然后执行下述查询。
select * from 表名;
查询一次数据,然后执行 show profiles;
,(该语句用来查看上一条SQL语句的开销信息)

在展示出的 profiles
【剖析】中找到 QueryID
,然后在使用如下命令查看详情。
show profile for query query_id;
例如使用刚刚得到的 QueryID
,即 97
进行查询。
show profile for query 97;

如果查询 profiles
的同时查看了 CPU
相关值。
show profile cpu for query 97;
-
CPU_user
:当前用户占用的 CPU; -
CPU_system
:当前系统占用的CPU。
查看 MEMORY
部分的开销,不过这个应该是还没有实现,查询之后并无效果。
show profile memory for query 47
查看 io
部分的开销。
show profile block io for query 3
查看所有参数,使用如下命令:
show profile all for query 41
在未来的版本中 show profiles;
可能不在支持,建议使用 Performance Schema
,具体命令如下所示
select * from information_schema.profiling
接下来重点说明下表内容

-
System lock
:内核锁; -
Sending data
:从服务端发送到客户端的数据,数据量大时会出现耗时长情况,注意该内容不是网络发送,是硬盘读取;
如果学习更多可以借助一下官方手册 show-profile。
记录时间
今天是持续写作的第 <font color=red>287</font> / 365 天。
可以<font color=#04a9f4>关注</font>我,<font color=#04a9f4>点赞</font>我、<font color=#04a9f4>评论</font>我、<font color=#04a9f4>收藏</font>我啦。
更多精彩
<kbd>[图片上传失败...(image-37999b-1643069363644)]

</kbd>
<center>
👇👇👇扫码加入【78技术人】~ Python 事业部👇👇👇</center>
网友评论