MySQL学习笔记之SQL语句执行过程查看
文章目录
- 参数使能
- 查看最近一条SQL执行过程
- 查看profiling打开开后,所有SQL语句执行耗时
- 查看某一条SQL的执行过程
- 指定要查看的性能选项
- 查看所有性能选项
参数使能
以select
语句为例,首先打开profile
参数:
mysql> set profiling = 1;
Query OK, 0 rows affected, 1 warning (0.00 sec)
然后执行两边下面的语句:
mysql> select * from employees;
查看最近一条SQL执行过程
可以通过show profile
语句查看最近一条SQL的执行过程:
mysql> show profile;
+----------------------+----------+
| Status | Duration |
+----------------------+----------+
| starting | 0.000039 |
| checking permissions | 0.000004 |
| Opening tables | 0.000012 |
| init | 0.000014 |
| System lock | 0.000006 |
| optimizing | 0.000002 |
| statistics | 0.000008 |
| preparing | 0.000010 |
| executing | 0.000003 |
| Sending data | 0.000188 |
| end | 0.000004 |
| query end | 0.000006 |
| closing tables | 0.000008 |
| freeing items | 0.000104 |
| cleaning up | 0.000013 |
+----------------------+----------+
15 rows in set, 1 warning (0.00 sec)
可以看到一条SQL语句要经历上述15步。如果开启了SQL缓存且命中缓存的话,步骤会减少,但SQL缓存要求两条SQL必须完全一样才能命中,任何字符的更改(包括注释、空格等)都会导致缓存没命中,因此MySQL的缓存相当鸡肋,命中率很低。
查看profiling打开开后,所有SQL语句执行耗时
可以通过show profiles
开启profiling
后所有SQL语句的耗时:
mysql> show profiles;
+----------+------------+-------------------------+
| Query_ID | Duration | Query |
+----------+------------+-------------------------+
| 1 | 0.00070175 | select * from employees |
| 2 | 0.00041950 | select * from employees |
+----------+------------+-------------------------+
2 rows in set, 1 warning (0.00 sec)
查看某一条SQL的执行过程
可以通过show profile for query Query_ID
查看:
mysql> show profile for query 1;
+----------------------+----------+
| Status | Duration |
+----------------------+----------+
| starting | 0.000036 |
| checking permissions | 0.000004 |
| Opening tables | 0.000012 |
| init | 0.000013 |
| System lock | 0.000006 |
| optimizing | 0.000002 |
| statistics | 0.000008 |
| preparing | 0.000355 |
| executing | 0.000006 |
| Sending data | 0.000169 |
| end | 0.000003 |
| query end | 0.000005 |
| closing tables | 0.000006 |
| freeing items | 0.000070 |
| cleaning up | 0.000007 |
+----------------------+----------+
15 rows in set, 1 warning (0.00 sec)mysql> show profile for query 2;
+----------------------+----------+
| Status | Duration |
+----------------------+----------+
| starting | 0.000039 |
| checking permissions | 0.000004 |
| Opening tables | 0.000012 |
| init | 0.000014 |
| System lock | 0.000006 |
| optimizing | 0.000002 |
| statistics | 0.000008 |
| preparing | 0.000010 |
| executing | 0.000003 |
| Sending data | 0.000188 |
| end | 0.000004 |
| query end | 0.000006 |
| closing tables | 0.000008 |
| freeing items | 0.000104 |
| cleaning up | 0.000013 |
+----------------------+----------+
15 rows in set, 1 warning (0.00 sec)
指定要查看的性能选项
mysql> show profile CPU, block io;
+---------------+----------+----------+------------+--------------+---------------+
| Status | Duration | CPU_user | CPU_system | Block_ops_in | Block_ops_out |
+---------------+----------+----------+------------+--------------+---------------+
| starting | 0.000066 | 0.000000 | 0.000000 | NULL | NULL |
| freeing items | 0.000058 | 0.000000 | 0.000000 | NULL | NULL |
| cleaning up | 0.000004 | 0.000000 | 0.000000 | NULL | NULL |
+---------------+----------+----------+------------+--------------+---------------+
3 rows in set, 1 warning (0.00 sec)
查看所有性能选项
mysql> show profile all for query 1\G
*************************** 1. row ***************************Status: startingDuration: 0.000036CPU_user: 0.000000CPU_system: 0.000000Context_voluntary: NULL
Context_involuntary: NULLBlock_ops_in: NULLBlock_ops_out: NULLMessages_sent: NULLMessages_received: NULLPage_faults_major: NULLPage_faults_minor: NULLSwaps: NULLSource_function: NULLSource_file: NULLSource_line: NULL
*************************** 2. row ***************************Status: checking permissionsDuration: 0.000004CPU_user: 0.000000CPU_system: 0.000000Context_voluntary: NULL
Context_involuntary: NULLBlock_ops_in: NULLBlock_ops_out: NULLMessages_sent: NULLMessages_received: NULLPage_faults_major: NULLPage_faults_minor: NULLSwaps: NULLSource_function: check_accessSource_file: sql_authorization.ccSource_line: 802
*************************** 3. row ***************************Status: Opening tablesDuration: 0.000012CPU_user: 0.000000CPU_system: 0.000000Context_voluntary: NULL
Context_involuntary: NULLBlock_ops_in: NULLBlock_ops_out: NULLMessages_sent: NULLMessages_received: NULLPage_faults_major: NULLPage_faults_minor: NULLSwaps: NULLSource_function: open_tablesSource_file: sql_base.ccSource_line: 5714
*************************** 4. row ***************************Status: initDuration: 0.000013CPU_user: 0.000000CPU_system: 0.000000Context_voluntary: NULL
Context_involuntary: NULLBlock_ops_in: NULLBlock_ops_out: NULLMessages_sent: NULLMessages_received: NULLPage_faults_major: NULLPage_faults_minor: NULLSwaps: NULLSource_function: handle_querySource_file: sql_select.ccSource_line: 121
*************************** 5. row ***************************Status: System lockDuration: 0.000006CPU_user: 0.000000CPU_system: 0.000000Context_voluntary: NULL
Context_involuntary: NULLBlock_ops_in: NULLBlock_ops_out: NULLMessages_sent: NULLMessages_received: NULLPage_faults_major: NULLPage_faults_minor: NULLSwaps: NULLSource_function: mysql_lock_tablesSource_file: lock.ccSource_line: 323
*************************** 6. row ***************************Status: optimizingDuration: 0.000002CPU_user: 0.000000CPU_system: 0.000000Context_voluntary: NULL
Context_involuntary: NULLBlock_ops_in: NULLBlock_ops_out: NULLMessages_sent: NULLMessages_received: NULLPage_faults_major: NULLPage_faults_minor: NULLSwaps: NULLSource_function: JOIN::optimizeSource_file: sql_optimizer.ccSource_line: 151
*************************** 7. row ***************************Status: statisticsDuration: 0.000008CPU_user: 0.000000CPU_system: 0.000000Context_voluntary: NULL
Context_involuntary: NULLBlock_ops_in: NULLBlock_ops_out: NULLMessages_sent: NULLMessages_received: NULLPage_faults_major: NULLPage_faults_minor: NULLSwaps: NULLSource_function: JOIN::optimizeSource_file: sql_optimizer.ccSource_line: 367
*************************** 8. row ***************************Status: preparingDuration: 0.000355CPU_user: 0.000000CPU_system: 0.000000Context_voluntary: NULL
Context_involuntary: NULLBlock_ops_in: NULLBlock_ops_out: NULLMessages_sent: NULLMessages_received: NULLPage_faults_major: NULLPage_faults_minor: NULLSwaps: NULLSource_function: JOIN::optimizeSource_file: sql_optimizer.ccSource_line: 475
*************************** 9. row ***************************Status: executingDuration: 0.000006CPU_user: 0.000000CPU_system: 0.000000Context_voluntary: NULL
Context_involuntary: NULLBlock_ops_in: NULLBlock_ops_out: NULLMessages_sent: NULLMessages_received: NULLPage_faults_major: NULLPage_faults_minor: NULLSwaps: NULLSource_function: JOIN::execSource_file: sql_executor.ccSource_line: 119
*************************** 10. row ***************************Status: Sending dataDuration: 0.000169CPU_user: 0.000000CPU_system: 0.000000Context_voluntary: NULL
Context_involuntary: NULLBlock_ops_in: NULLBlock_ops_out: NULLMessages_sent: NULLMessages_received: NULLPage_faults_major: NULLPage_faults_minor: NULLSwaps: NULLSource_function: JOIN::execSource_file: sql_executor.ccSource_line: 195
*************************** 11. row ***************************Status: endDuration: 0.000003CPU_user: 0.000000CPU_system: 0.000000Context_voluntary: NULL
Context_involuntary: NULLBlock_ops_in: NULLBlock_ops_out: NULLMessages_sent: NULLMessages_received: NULLPage_faults_major: NULLPage_faults_minor: NULLSwaps: NULLSource_function: handle_querySource_file: sql_select.ccSource_line: 199
*************************** 12. row ***************************Status: query endDuration: 0.000005CPU_user: 0.000000CPU_system: 0.000000Context_voluntary: NULL
Context_involuntary: NULLBlock_ops_in: NULLBlock_ops_out: NULLMessages_sent: NULLMessages_received: NULLPage_faults_major: NULLPage_faults_minor: NULLSwaps: NULLSource_function: mysql_execute_commandSource_file: sql_parse.ccSource_line: 4946
*************************** 13. row ***************************Status: closing tablesDuration: 0.000006CPU_user: 0.000000CPU_system: 0.000000Context_voluntary: NULL
Context_involuntary: NULLBlock_ops_in: NULLBlock_ops_out: NULLMessages_sent: NULLMessages_received: NULLPage_faults_major: NULLPage_faults_minor: NULLSwaps: NULLSource_function: mysql_execute_commandSource_file: sql_parse.ccSource_line: 4998
*************************** 14. row ***************************Status: freeing itemsDuration: 0.000070CPU_user: 0.000000CPU_system: 0.000000Context_voluntary: NULL
Context_involuntary: NULLBlock_ops_in: NULLBlock_ops_out: NULLMessages_sent: NULLMessages_received: NULLPage_faults_major: NULLPage_faults_minor: NULLSwaps: NULLSource_function: mysql_parseSource_file: sql_parse.ccSource_line: 5610
*************************** 15. row ***************************Status: cleaning upDuration: 0.000007CPU_user: 0.000000CPU_system: 0.000000Context_voluntary: NULL
Context_involuntary: NULLBlock_ops_in: NULLBlock_ops_out: NULLMessages_sent: NULLMessages_received: NULLPage_faults_major: NULLPage_faults_minor: NULLSwaps: NULLSource_function: dispatch_commandSource_file: sql_parse.ccSource_line: 1924
15 rows in set, 1 warning (0.00 sec)
举其中的一行为例:*************************** 10. row ***************************Status: Sending dataDuration: 0.000169CPU_user: 0.000000CPU_system: 0.000000Context_voluntary: NULL
Context_involuntary: NULLBlock_ops_in: NULLBlock_ops_out: NULLMessages_sent: NULLMessages_received: NULLPage_faults_major: NULLPage_faults_minor: NULLSwaps: NULLSource_function: JOIN::execSource_file: sql_executor.ccSource_line: 195
每一行数据就显示该步骤下的各个阶段的耗时,甚至源文件等信息。
相关文章:
MySQL学习笔记之SQL语句执行过程查看
文章目录 参数使能查看最近一条SQL执行过程查看profiling打开开后,所有SQL语句执行耗时查看某一条SQL的执行过程指定要查看的性能选项查看所有性能选项 参数使能 以select语句为例,首先打开profile参数: mysql> set profiling 1; Query…...

如何以毫秒精度,查看系统时间以及文件的创建时间
用 cmd 查看系统的时间: powershell -command "(Get-Date -UFormat %Y-%m-%d %H:%M:%S).toString() . ((Get-Date).millisecond)" 用 XYplorer 查看文件的精确创建时间(含30天试用): XYplorer - File Manager for …...

基于机器学习的情绪识别算法matlab仿真,对比SVM,LDA以及决策树
目录 1.算法理论概述 2.部分核心程序 3.算法运行软件版本 4.算法运行效果图预览 5.算法完整程序工程 1.算法理论概述 情绪识别是一种重要的情感分析任务,旨在从文本、语音或图像等数据中识别出人的情绪状态,如高兴、悲伤、愤怒等。本文介绍一种基于…...

jMeter使用随记
参数化BodyData 先制作参数文件 再设置一个csv data set config 最后在body data里面写上参数${xxxxx}...

[语义分割] DeepLab v3(Cascaded model、ASPP model、两种ASPP对比、Multi-grid、训练细节)
Rethinking Atrous Convolution for Semantic Image Segmentation 论文地址:Rethinking Atrous Convolution for Semantic Image SegmentationPytorch 实现代码:pytorch_segmentation/deeplab_v3 这是一篇 2017 年发表在CVPR上的文章。相比 DeepLab V2 有…...

css - Media Query
使用bootstrap的grid system可以在一个较为粗糙的范围得到较好的响应性,但是通过viewport可以看到网站在具体哪个像素点处变得丑陋,再通过css media query来精细调整网页布局。 可以通过media query来提高网页移动响应能力。...

9.python设计模式【外观模式】
内容:为子系统中的一组接口提供一个一致的界面,外观模式定义了一个高层接口,这个接口使得这一个子系统更加容易使用。 角色: 外观(facade)子类系统(subsystem classes) UML图 举…...
Webpack5 CopyPlugin的作用
在Webpack 5中,CopyPlugin是一个插件,用于将文件或目录从源位置复制到构建目录中。它的作用是帮助开发人员在构建过程中将静态文件(如图片、字体等)直接复制到输出目录,而无需经过任何处理。 CopyPlugin并不是必须的&…...
kafka服务端允许生产者发送最大消息体大小
1、kafka config服务端配置文件server.properties server.properties中加上的message.max.bytes配置,我目前设置为5242880,即5MB,可以根据实际情况增大。 message.max.bytes5242880 在生产者端配置max.request.size,这是单个消息…...
台阶型Nim游戏博弈论
台阶型Nim游戏 题目 https://www.acwing.com/problem/content/894/ 现在,有一个 n n n 级台阶的楼梯,每级台阶上都有若干个石子,其中第 i i i 级台阶上有 a i a_i ai 个石子( i ≥ 1 i \ge 1 i≥1)。 两位玩家轮流操作,每…...
NestJS 的 中间件 学习
基本概念 中间件是在路由处理程序之前调用的函数。中间件函数可以访问请求和响应对象。在程序中我们可以让多个中间件串起来一起使用,当多个中间件一起使用时我们可以使用next()调用下一个中间件。 中间件主要是可以实现如下功能: 执行任何代码更改请…...

搭建自己第一个golang程序
概念: golang 和 java有些类似,配置好环境就可以直接编写运行了;这里分两种: 一.shell模式 创建一个go类型的文件 往里面编写代码 二.开发工具模式 这里的开发工具 我选用goland package mainimport "fmt"func mai…...

Mysql加锁过程
1、背景 MySQL/InnoDB的加锁分析,一直是一个比较困难的话题。我在工作过程中,经常会有同事咨询这方面的问题。同时,微博上也经常会收到MySQL锁相关的私信,让我帮助解决一些死锁的问题。本文,准备就MySQL/InnoDB的加锁问…...
财经界杂志财经界杂志社财经界编辑部2023年第19期目录
《财经界》投稿邮箱:cnqikantg126.com(注明投稿“《财经界》”) ●崔编辑Q Q :695548262 微信号:f99832970 名刊名著_国内外名刊名著 财经名刊名著 李少鹏 ;王海蕴; 6-7 发改委专线 六方面发力 看中国经济形势,既要看准当…...

Linux常用命令——dpkg-split命令
在线Linux命令查询工具 dpkg-split Debian Linux中将大软件包分割成小包 补充说明 dpkg-split命令用来将Debian Linux中的大软件包分割成小软件包,它还能够将已分割的文件进行合并。 语法 dpkg-split(选项)(参数)选项 -S:设置分割后的每个小文件最…...

常见的二十种软件测试方法详解
一.单元测试(模块测试) 单元测试是对软件组成单元进行测试。其目的是检验软件组成单位的正确性。测试对象是:模块。 对模块进行测试,单独的一个模块测试,属于静态测试的一类 测试阶段:编码后或者编码前&…...

Python(一)
要做到坚韧不拔,最要紧的是坚持到底。——陀思妥耶夫斯基 2023 6 14~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ --根据你自己的操作系统下载对应的。 -- pyhton 文档 --交互方式 使用的工具 --如何启动工具 -- 交互式方式一般在数据分析中…...

git pull无效,显示 * branch master -> FETCH_HEADAlready up to date. pull无效解决方法
报错情况 本地文件夹中删除文件后,git pull无效。显示如下: **** MINGW64 ~/****/haha (master) $ git pull origin master From https://gitee.com/****/haha* branch master -> FETCH_HEAD Already up to date.解决 方法一 命令…...
SK5代理与socks5代理
第一部分:SK5代理与socks5代理的原理与功能 SK5代理 SK5代理是一种加密代理技术,其工作原理主要包括以下几个关键步骤: 代理服务器接收客户端请求;客户端与代理服务器之间建立加密连接;代理服务器将客户端的请求转发…...
【【51单片机红外遥控小风车】】
51单片机红外遥控小风车 今天结束了51单片机的学习,明天开始学习stm32 我是学习江科大的视频一步一步完成的 ,他讲的非常好,非常好 特别通俗易懂 学习复刻他的作品我也自己创作了一些 但是现在暂时脱离这块板子了 以后可能会更新一个应用51单…...

Spark 之 入门讲解详细版(1)
1、简介 1.1 Spark简介 Spark是加州大学伯克利分校AMP实验室(Algorithms, Machines, and People Lab)开发通用内存并行计算框架。Spark在2013年6月进入Apache成为孵化项目,8个月后成为Apache顶级项目,速度之快足见过人之处&…...
在HarmonyOS ArkTS ArkUI-X 5.0及以上版本中,手势开发全攻略:
在 HarmonyOS 应用开发中,手势交互是连接用户与设备的核心纽带。ArkTS 框架提供了丰富的手势处理能力,既支持点击、长按、拖拽等基础单一手势的精细控制,也能通过多种绑定策略解决父子组件的手势竞争问题。本文将结合官方开发文档,…...
基于服务器使用 apt 安装、配置 Nginx
🧾 一、查看可安装的 Nginx 版本 首先,你可以运行以下命令查看可用版本: apt-cache madison nginx-core输出示例: nginx-core | 1.18.0-6ubuntu14.6 | http://archive.ubuntu.com/ubuntu focal-updates/main amd64 Packages ng…...
服务器硬防的应用场景都有哪些?
服务器硬防是指一种通过硬件设备层面的安全措施来防御服务器系统受到网络攻击的方式,避免服务器受到各种恶意攻击和网络威胁,那么,服务器硬防通常都会应用在哪些场景当中呢? 硬防服务器中一般会配备入侵检测系统和预防系统&#x…...

转转集团旗下首家二手多品类循环仓店“超级转转”开业
6月9日,国内领先的循环经济企业转转集团旗下首家二手多品类循环仓店“超级转转”正式开业。 转转集团创始人兼CEO黄炜、转转循环时尚发起人朱珠、转转集团COO兼红布林CEO胡伟琨、王府井集团副总裁祝捷等出席了开业剪彩仪式。 据「TMT星球」了解,“超级…...

BCS 2025|百度副总裁陈洋:智能体在安全领域的应用实践
6月5日,2025全球数字经济大会数字安全主论坛暨北京网络安全大会在国家会议中心隆重开幕。百度副总裁陈洋受邀出席,并作《智能体在安全领域的应用实践》主题演讲,分享了在智能体在安全领域的突破性实践。他指出,百度通过将安全能力…...

零基础设计模式——行为型模式 - 责任链模式
第四部分:行为型模式 - 责任链模式 (Chain of Responsibility Pattern) 欢迎来到行为型模式的学习!行为型模式关注对象之间的职责分配、算法封装和对象间的交互。我们将学习的第一个行为型模式是责任链模式。 核心思想:使多个对象都有机会处…...
Java求职者面试指南:计算机基础与源码原理深度解析
Java求职者面试指南:计算机基础与源码原理深度解析 第一轮提问:基础概念问题 1. 请解释什么是进程和线程的区别? 面试官:进程是程序的一次执行过程,是系统进行资源分配和调度的基本单位;而线程是进程中的…...
Git常用命令完全指南:从入门到精通
Git常用命令完全指南:从入门到精通 一、基础配置命令 1. 用户信息配置 # 设置全局用户名 git config --global user.name "你的名字"# 设置全局邮箱 git config --global user.email "你的邮箱example.com"# 查看所有配置 git config --list…...

PHP 8.5 即将发布:管道操作符、强力调试
前不久,PHP宣布了即将在 2025 年 11 月 20 日 正式发布的 PHP 8.5!作为 PHP 语言的又一次重要迭代,PHP 8.5 承诺带来一系列旨在提升代码可读性、健壮性以及开发者效率的改进。而更令人兴奋的是,借助强大的本地开发环境 ServBay&am…...