用show profile查询工具指定具体的type

show profile在mysql5.7之后过时

show profile命令用于跟踪执行过的sql语句的资源消耗信息,可以帮助查看sql语句的执行情况,可以在做性能分析或者问题诊断的时候作为参考。在MySQL5.7中, show profile命令已经开始不推荐使用,MySQL使用performance_schema 中系统表的信息来替代show profile命令,这儿主要是研究资源性能监控的思路。

SHOW PROFILE [type [, type] ... ]
[FOR QUERY n]
[LIMIT row_count [OFFSET offset]] type:
ALL
| BLOCK IO
| CONTEXT SWITCHES
| CPU
| IPC
| MEMORY
| PAGE FAULTS
| SOURCE
| SWAPS

此工具默认是禁用的,首先打开show profile跟踪记录SQL执行情况的配置,可以通过服务器变量在会话级别动态的修改:

mysql> set profiling = 1;
Query OK, 0 rows affected, 1 warning (0.00 sec)

当设置完成之后,在服务器上执行的所有语句,都会测量其耗费的时间和其他一些查询执行状态变更相关的数据。

以下面查询语句举例:

mysql> select * from emp;
+-------+--------+-----------+------+------------+---------+---------+--------+
| empno | ename | job | mgr | hiredate | sal | comm | deptno |
+-------+--------+-----------+------+------------+---------+---------+--------+
| 7369 | SMITH | CLERK | 7902 | 1980-12-17 | 800.00 | NULL | 20 |
| 7499 | ALLEN | SALESMAN | 7698 | 1981-02-20 | 1600.00 | 300.00 | 30 |
| 7521 | WARD | SALESMAN | 7698 | 1981-02-22 | 1250.00 | 500.00 | 30 |
| 7566 | JONES | MANAGER | 7839 | 1981-04-02 | 2975.00 | NULL | 20 |
| 7654 | MARTIN | SALESMAN | 7698 | 1981-09-28 | 1250.00 | 1400.00 | 30 |
| 7698 | BLAKE | MANAGER | 7839 | 1981-05-01 | 2850.00 | NULL | 30 |
| 7782 | CLARK | MANAGER | 7839 | 1981-06-09 | 2450.00 | NULL | 10 |
| 7788 | SCOTT | ANALYST | 7566 | 1987-07-13 | 3000.00 | NULL | 20 |
| 7839 | KING | PRESIDENT | NULL | 1981-11-17 | 5000.00 | NULL | 10 |
| 7844 | TURNER | SALESMAN | 7698 | 1981-09-08 | 1500.00 | 0.00 | 30 |
| 7876 | ADAMS | CLERK | 7788 | 1987-07-13 | 1100.00 | NULL | 20 |
| 7900 | JAMES | CLERK | 7698 | 1981-12-03 | 950.00 | NULL | 30 |
| 7902 | FORD | ANALYST | 7566 | 1981-12-03 | 3000.00 | NULL | 20 |
| 7934 | MILLER | CLERK | 7782 | 1982-01-23 | 1300.00 | NULL | 10 |
+-------+--------+-----------+------+------------+---------+---------+--------+
14 rows in set (0.01 sec)

在mysql的命令行模式下只能显示两位小数的时间,可以使用如下命令查看具体的执行时间

mysql> show profiles;
+----------+------------+-------------------+
| Query_ID | Duration | Query |
+----------+------------+-------------------+
| 1 | 0.00130500 | show databases |
| 2 | 0.00010250 | SELECT DATABASE() |
| 3 | 0.00027500 | show databases |
| 4 | 0.00023075 | show tables |
| 5 | 0.00041800 | show databases |
| 6 | 0.00018925 | show tables |
| 7 | 0.00376825 | select * from emp |
+----------+------------+-------------------+
7 rows in set, 1 warning (0.00 sec)

上面一共有7条sql语句操作,执行如下命令可以查看详细的每个步骤的时间,这儿以Query_ID = 1的语句举例子:

mysql> show profile for query 1 ;
+----------------------+----------+
| Status | Duration |
+----------------------+----------+
| starting | 0.000089 |
| checking permissions | 0.000025 |
| Opening tables | 0.000062 |
| init | 0.000036 |
| System lock | 0.000007 |
| optimizing | 0.000004 |
| statistics | 0.000023 |
| preparing | 0.000039 |
| executing | 0.000910 |
| Sending data | 0.000019 |
| end | 0.000016 |
| query end | 0.000006 |
| closing tables | 0.000002 |
| removing tmp table | 0.000004 |
| closing tables | 0.000016 |
| freeing items | 0.000013 |
| cleaning up | 0.000036 |
+----------------------+----------+
17 rows in set, 1 warning (0.00 sec)

除了query n指定Query_ID外,还可以设置Type查看MYSQL语句执行的其他信息,type主要参数如下:

all:显示所有性能信息

block io:显示块io操作的次数

context switches:显示上下文切换次数,被动和主动

cpu:显示用户cpu时间、系统cpu时间

IPC:显示发送和接受的消息数量

Memory:暂未实现

page faults:显示页错误数量

source:显示源码中的函数名称与位置

swaps:显示swap的次数

##all显示内容太宽,这儿暂不显示
mysql> show profile all for query 7;

block io

# block io
mysql> mysql> show profile block io fo 7;
+----------------------+----------+--------------+---------------+
| Status | Duration | Block_ops_in | Block_ops_out |
+----------------------+----------+--------------+---------------+
| starting | 0.000053 | 0 | 0 |
| checking permissions | 0.000006 | 0 | 0 |
| Opening tables | 0.000014 | 0 | 0 |
| init | 0.000056 | 0 | 0 |
| System lock | 0.000055 | 0 | 0 |
| optimizing | 0.000006 | 0 | 0 |
| statistics | 0.000008 | 0 | 0 |
| preparing | 0.000007 | 0 | 0 |
| executing | 0.000002 | 0 | 0 |
| Sending data | 0.003099 | 0 | 0 |
| end | 0.000006 | 0 | 0 |
| query end | 0.000007 | 0 | 0 |
| closing tables | 0.000006 | 0 | 0 |
| freeing items | 0.000396 | 0 | 0 |
| cleaning up | 0.000050 | 0 | 0 |
+----------------------+----------+--------------+---------------+
15 rows in set, 1 warning (0.00 sec)

context switches

#context switches
mysql> show profile context switches for query 1;
+----------------------+----------+-------------------+---------------------+
| Status | Duration | Context_voluntary | Context_involuntary |
+----------------------+----------+-------------------+---------------------+
| starting | 0.000089 | 0 | 0 |
| checking permissions | 0.000025 | 0 | 0 |
| Opening tables | 0.000062 | 0 | 0 |
| init | 0.000036 | 0 | 0 |
| System lock | 0.000007 | 0 | 0 |
| optimizing | 0.000004 | 0 | 0 |
| statistics | 0.000023 | 0 | 0 |
| preparing | 0.000039 | 0 | 0 |
| executing | 0.000910 | 0 | 0 |
| Sending data | 0.000019 | 0 | 0 |
| end | 0.000016 | 0 | 0 |
| query end | 0.000006 | 0 | 0 |
| closing tables | 0.000002 | 0 | 0 |
| removing tmp table | 0.000004 | 0 | 0 |
| closing tables | 0.000016 | 0 | 0 |
| freeing items | 0.000013 | 0 | 0 |
| cleaning up | 0.000036 | 0 | 0 |
+----------------------+----------+-------------------+---------------------+
17 rows in set, 1 warning (0.00 sec)

cpu

#cpu
mysql> show profile cpu for query 7;
+----------------------+----------+----------+------------+
| Status | Duration | CPU_user | CPU_system |
+----------------------+----------+----------+------------+
| starting | 0.000053 | 0.000000 | 0.000000 |
| checking permissions | 0.000006 | 0.000000 | 0.000000 |
| Opening tables | 0.000014 | 0.000000 | 0.000000 |
| init | 0.000056 | 0.000000 | 0.000000 |
| System lock | 0.000055 | 0.000000 | 0.000000 |
| optimizing | 0.000006 | 0.000000 | 0.000000 |
| statistics | 0.000008 | 0.000000 | 0.000000 |
| preparing | 0.000007 | 0.000000 | 0.000000 |
| executing | 0.000002 | 0.000000 | 0.000000 |
| Sending data | 0.003099 | 0.002000 | 0.000000 |
| end | 0.000006 | 0.000000 | 0.000000 |
| query end | 0.000007 | 0.000000 | 0.000000 |
| closing tables | 0.000006 | 0.000000 | 0.000000 |
| freeing items | 0.000396 | 0.001000 | 0.000000 |
| cleaning up | 0.000050 | 0.000000 | 0.000000 |
+----------------------+----------+----------+------------+
15 rows in set, 1 warning (0.00 sec)

ipc

#ipc
mysql> show profile ipc for query 1;
+----------------------+----------+---------------+-------------------+
| Status | Duration | Messages_sent | Messages_received |
+----------------------+----------+---------------+-------------------+
| starting | 0.000089 | 0 | 0 |
| checking permissions | 0.000025 | 0 | 0 |
| Opening tables | 0.000062 | 0 | 0 |
| init | 0.000036 | 0 | 0 |
| System lock | 0.000007 | 0 | 0 |
| optimizing | 0.000004 | 0 | 0 |
| statistics | 0.000023 | 0 | 0 |
| preparing | 0.000039 | 0 | 0 |
| executing | 0.000910 | 0 | 0 |
| Sending data | 0.000019 | 0 | 0 |
| end | 0.000016 | 0 | 0 |
| query end | 0.000006 | 0 | 0 |
| closing tables | 0.000002 | 0 | 0 |
| removing tmp table | 0.000004 | 0 | 0 |
| closing tables | 0.000016 | 0 | 0 |
| freeing items | 0.000013 | 0 | 0 |
| cleaning up | 0.000036 | 0 | 0 |
+----------------------+----------+---------------+-------------------+
17 rows in set, 1 warning (0.00 sec)

page faults

# page faults
mysql> show profile page faults for query 1;
+----------------------+----------+-------------------+-------------------+
| Status | Duration | Page_faults_major | Page_faults_minor |
+----------------------+----------+-------------------+-------------------+
| starting | 0.000089 | 0 | 0 |
| checking permissions | 0.000025 | 0 | 0 |
| Opening tables | 0.000062 | 0 | 0 |
| init | 0.000036 | 0 | 0 |
| System lock | 0.000007 | 0 | 0 |
| optimizing | 0.000004 | 0 | 0 |
| statistics | 0.000023 | 0 | 0 |
| preparing | 0.000039 | 0 | 0 |
| executing | 0.000910 | 0 | 1 |
| Sending data | 0.000019 | 0 | 0 |
| end | 0.000016 | 0 | 0 |
| query end | 0.000006 | 0 | 0 |
| closing tables | 0.000002 | 0 | 0 |
| removing tmp table | 0.000004 | 0 | 0 |
| closing tables | 0.000016 | 0 | 0 |
| freeing items | 0.000013 | 0 | 0 |
| cleaning up | 0.000036 | 0 | 0 |
+----------------------+----------+-------------------+-------------------+
17 rows in set, 1 warning (0.00 sec)

source

swaps

# swaps
mysql> show profile swaps for query 7;
+----------------------+----------+-------+
| Status | Duration | Swaps |
+----------------------+----------+-------+
| starting | 0.000053 | 0 |
| checking permissions | 0.000006 | 0 |
| Opening tables | 0.000014 | 0 |
| init | 0.000056 | 0 |
| System lock | 0.000055 | 0 |
| optimizing | 0.000006 | 0 |
| statistics | 0.000008 | 0 |
| preparing | 0.000007 | 0 |
| executing | 0.000002 | 0 |
| Sending data | 0.003099 | 0 |
| end | 0.000006 | 0 |
| query end | 0.000007 | 0 |
| closing tables | 0.000006 | 0 |
| freeing items | 0.000396 | 0 |
| cleaning up | 0.000050 | 0 |
+----------------------+----------+-------+
15 rows in set, 1 warning (0.00 sec)

MySQL调优性能监控之show profile的更多相关文章

  1. MySQL调优性能监控之performance schema

    一.performance_schema的介绍 performance:性能 schema:图(表)示,以大纲或模型的形式表示计划或理论. MySQL的performance schema 用于监控M ...

  2. MySQL(调优慢查询、explain profile) 转

    转自http://www.linuxidc.com/Linux/2012-09/70459.htm mysql profile explain slow_query_log分析优化查询 在做性能测试中 ...

  3. MySQL调优用户监控之show processlist

    简介 show processlist显示这台MySQL正在连接的用户: mysql> show processlist; +----+------+-----------+-------+-- ...

  4. MySQL 调优/优化的 100 个建议

    MySQL 调优/优化的 100 个建议   MySQL是一个强大的开源数据库.随着MySQL上的应用越来越多,MySQL逐渐遇到了瓶颈.这里提供 101 条优化 MySQL 的建议.有些技巧适合特定 ...

  5. mysql调优学习笔记

    性能监控 使用show profile查询剖析工具,可以指定具体的type 此工具默认是禁用的,可以通过服务器变量在绘画级别动态的修改 set profiling=1; 当设置完成之后,在服务器上执行 ...

  6. MySQL 调优基础(一) CPU与进程

    一般而言,MySQL 的调优可以分为两个层面,一个是在MySQL层面上进行的调优,比如SQL改写,索引的添加,MySQL各种参数的配置:另一个层面是从操作系统的层面和硬件的层面来进行调优.操作系统的层 ...

  7. MySQL调优系列基础篇

    前言 有一段时间没有写博客了,整天都在忙,上班,录制课程,恰巧最近一段时间比较清闲,打算弄弄MYSQL数据库. 关于MySQL数据库,这里就不做过多的介绍,开源.免费等特性深受各个互联网行业喜爱,尤其 ...

  8. mysql调优 基础

    MySQL调优可以从几个方面来做: 1. 架构层:做从库,实现读写分离: 2.系统层次:增加内存:给磁盘做raid0或者raid5以增加磁盘的读写速度:可以重新挂载磁盘,并加上noatime参数,这样 ...

  9. MySQL调优 —— Using temporary

      DBA发来一个线上慢查询问题. SQL例如以下(为突出重点省略部分内容): select distinct article0_.id, 等字段 from article_table article ...

随机推荐

  1. 【程序包管理】Linux软件管理之src源码安装编译

    在很多时候我们需要自定义软件的特性,这时就需要用到源码安装.那么,网上有很多编译源码的工具,那么,我们怎么知道别人使用的是什么工具呢.其实我也不知道(*^▽^*). 那么本篇博客主要是写C代码的源码安 ...

  2. IDEA控制台打印程序内汉字乱码及txt文本乱码

    控制台打印汉字乱码 解决IntelliJ IDEA控制台输出中文乱码问题 txt文本乱码 解决IDEA读取txt文本中显示的中文乱码问题

  3. 【Shiro学习之六】shiro编码/加密

    apahce shiro:1.6.0 密码存储,应该加密/生成密码摘要存储,而不是存储明文密码. 1.编码/解码Shiro 提供了 base64和 16进制字符串编码/解码的API支持, 方便一些编码 ...

  4. WebService的开发手段

    一.WebService的开发手段 目前有关webService的开发手段有2种 1.JDK开发(jdk必须是1.6及以上版本,因为jdk是在1.6版本中引入并支持webservice开发的); 2. ...

  5. 解析SwiftUI布局细节(二)循环轮播+复杂布局

    前言 上一篇我们总结的主要是VStack里面的东西,由他延伸到 @ViewBuilder, 接着我们上一篇总结的我们这篇内容主要说的是下面的几点,在这些东西说完后我准备解析一下苹果在SiwftUI文档 ...

  6. [强制]IDE使用UTF-8和LF

    Java 程序开发常用的集成开发环境(IDE)有Eclipse和IntelliJ IDEA.Eclipse是免费开源的,很多早期程序员使用它的比较多.IntelliJ IDEA有社区版和企业版,社区版 ...

  7. JAVA编程环境与基本数据类型

    <JAVA编程环境与基本数据类型> 随笔目录 # <JAVA编程环境与基本数据类型> 随笔目录 - Java小实例 java的编程环境 java数据类型 Java小实例 jav ...

  8. Windows搭建SkyWalking8.3环境进行JAVA应用性能监控及入门示例(使用Mysql持久化)

    下载SkyWalking 一.下载地址(点击) 选择tar 解压后进入config文件夹先配置一下Mysql数据源,打开application.yml文件 默认selector是h2我们改成mysql ...

  9. Sql Server Sum函数的特殊使用

    利用Sql Server的Sum函数开窗得到累计值 具体详解https://www.cnblogs.com/zhaoshujie/p/9594676.html 个人示例例子 DECLARE @Sale ...

  10. 7.shell脚本编程

    1.shell 脚本语言的基本用法 1.1shell 脚本创建 1.格式要求:首行shebang机制 #!/bin/bash #!/usr/bin/python #!/usr/bin/perl 2.添 ...