当前位置:网站首页>MySQL数据库:使用show profile命令分析性能
MySQL数据库:使用show profile命令分析性能
2022-06-29 13:05:00 【全栈程序员站长】
1、show profile的作用:
能够查出最近执行的SQL语句的运行状态,包括在运行过程中执行了哪些操作,各占用了多少时间,利用proflie 功能,可以分析一个SQL具体的执行代价是怎么样的,尤其是可以分析它的最大瓶颈在哪里。目前profile 功能可提供除了内存以外的其他资源消耗统计,例如CPU、I/O、CONTEXT、SWAP等。大部分情况下,profile 的结果我们主要关注两列:Status、Duration,前者表示的是profile 里的状态,后者是该状态的耗时。因此,我们最主要的是关注处于哪个状态耗时最久,这些状态中,哪些是可以进一步优化的。
2、show profile 语法:
SHOW PROFILE [type [, type] … ] [FOR QUERY n] [LIMIT row_count [OFFSET offset]] type参数: | ALL:显示所有开销信息 | BLOCK IO:阻塞的输入输出次数 | CONTEXT SWITCHES:上下文切换相关开销信息 | CPU:显示CPU的相关开销信息 | IPC:接收和发送消息的相关开销信息 | MEMORY :显示内存相关的开销,目前无用 | PAGE FAULTS :显示页面错误相关开销信息 | SOURCE :列出相应操作对应的函数名及其在源码中的调用位置(行数) | SWAPS:显示swap交换次数的相关开销信息 LIMIT row_count子句用于限制输出行数。
3、show profile / show profiles的使用:
show profile 以及 show profiles语句可以显示当前会话过程中执行的sql语句的性能(profiling)信息。
(1)profiling功能由MySQL会话变量 : profiling控制,默认是OFF关闭状态,查看当前session是否开启profile功能:
select @@profiling; show variables like ‘profiling’;
(2)开启profiling:
set profiling=ON;
(3)运行SQL:
随便运行几条SQL,以便show profiles 的日志分析。
(4)查看结果:
(4.1)show profiles
show profiles 显示最近发给服务器的多条语句,条数根据会话变量profiling_history_size定义,默认是15,最大值为100。设为0等价于关闭profiling 分析功能。除SHOW PROFILE和SHOW PROFILES之外,所有sql语句的性能信息都会被记录,甚至包括有错误的语句。
show profiles;
(4.2)show profile
用于单独分析最近一条执行的sql语句的详细资源占用信息和工作状况,默认显示状态以及它们持续的时间。
show profile;
可以给show profile 指定一个 for query id 来查看指定 id 的语句,还可以给输出添加新的列。如,查看用户和CPU使用。可以用如下命令。(详细参数请看本文第2点的type参数)
show profile cpu,block io for query id;
id 为 show profiles 查出来的某条记录的Query_ID。
4、作用范围:
(1)这个命令只是在本会话内起作用,即无法分析本会话外的语句。开启分析功能后,所有本会话中的语句都被分析(甚至包括执行错误的语句),除了SHOW PROFILE和SHOW PROFILES两句本身。
(2)profiling是会话级的,当会话结束,与之相关的profiling信息也会随之消失。
(3)profiling是针对进程(process)而非线程(threads),因此运行在服务器上的其他服务进程可能会影响分析结果.
发布者:全栈程序员栈长,转载请注明出处:https://javaforall.cn/100070.html原文链接:https://javaforall.cn
边栏推荐
- weserver发布地图服务
- 微信小程序:大红喜庆版UI猜灯谜又叫猜字谜
- 【系统设计】邻近服务
- 动荡的中介生意,不安的租房人
- Uncover the secret! Pay attention to those machines under the membership system!
- pdb符号库文件详解
- Weserver publishing map service
- mysql多表查询
- Online text filter less than specified length tool
- System. Currenttimemillis() and system Nanotime() which is faster? Most people get the wrong answer!
猜你喜欢

Yyds dry inventory solution sword finger offer: find the nearest common ancestor of two nodes in the binary tree

Openssl证书工具使用手册

揭秘百度智能测试在测试自动执行领域实践

WinDbg debugging tool introduction

Sixty years of deep learning

硬件开发笔记(八): 硬件开发基本流程,制作一个USB转RS232的模块(七):创建基础DIP元器件(晶振)封装并关联原理图元器件

Cloud native (31) | kubernetes chapter kubernetes platform basic pre installed resources

测试用例设计方法之等价类划分方法

在线文本过滤小于指定长度工具

微信小程序:装B神器P图修改微信流量主小程序源码下载趣味恶搞图制作免服务器域名
随机推荐
【系统设计】邻近服务
June training (day 29) - divide and rule
[system design] proximity service
Interview high concurrent, cool!! (high energy in the whole process, collection recommended)
Xiaobai learns MySQL - incremental statistical SQL requirements - windowing function scheme
Normalization layer of pytorch learning (batchnorm, layernorm, instancenorm, groupnorm) [easy to understand]
pdb符号库文件详解
Follow me study hcie big data mining Chapter 1 Introduction to data mining module 2
Teach you how to install the latest version of mysql8.0 database on windows, nanny level teaching
微信小程序:全新独家云开发微群人脉
微信小程序:修复采集接口版云开发表情包
STM32 watchdog study
grep 精确匹配
[untitled] error in installation dependency: refusing to install package with name "* * *" under a package
【云驻共创】通过Rust语言计算加速技术突破图片识别性能瓶颈
TikTok全球短视频霸主地位或被YouTube反超
靠代理,靠买断,国产端游的蛮荒时代等待下一个《永劫无间》
php-fpm 启动参数及重要配置详解
[cloud resident co creation] break through the performance bottleneck of image recognition through rust language computing acceleration technology
mysql函数和约束