PROFILE  可以跟踪查询语句各个阶段 Time,IO,CPU,MEMORY 等资源使用情况,比较详细。所以系统一般不会记录太多。启用是全局的,所以每个连接都保持语句的资源使用情况。

查看 PROFILE 是否启用:

mysql> select @@profiling;
+-------------+
| @@profiling |
+-------------+
| 0 |
+-------------+

mysql> show variables like '%profiling%';
+------------------------+-------+
| variable_name | value |
+------------------------+-------+
| have_profiling | yes |
| profiling | off |
| profiling_history_size | 15 |
+------------------------+-------+
have_profiling :是否可使用 profiling
profiling :是否启用
profiling_history_size : 保留最近执行的记录数量。默认15,最大100,0相当于禁用。

启用(为全局变量):

mysql> set profiling = 1;
mysql> set profiling_history_size = 10;
查看当前连接最近执行语句情况,编号越大为当前最近执行的。
mysql> show profiles;
+----------+------------+-----------------------------------------+
| query_id | duration | query |
+----------+------------+-----------------------------------------+
| 2 | 0.00705950 | show variables like '%profiling%' |
| 3 | 0.00127400 | select * from mysql.user |
| 4 | 0.00029100 | select * from mysql.user |
| 5 | 0.00040850 | select * from mysql.user limit 10 |
| 6 | 5.00128000 | select sleep(5) |
| 7 | 0.00044425 | select * from mysql.user limit 1 |
| 8 | 0.00436100 | show variables like '%profiling%' |
| 9 | 0.00047725 | select * from mysql.slow_log |
| 10 | 0.00052150 | select * from mysql.slow_log order by 1 |
| 11 | 0.00049775 | select * from mysql.slow_log order by 2 |
+----------+------------+-----------------------------------------+

查看以上查询开销:SHOW PROFILE Syntax
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

默认显示时间信息,显示了该查询从开始到被清除各个阶段的执行时间。
mysql> show profile;
+----------------------+----------+
| Status | Duration |
+----------------------+----------+
| starting | 0.000090 |
| checking permissions | 0.000007 |
| Opening tables | 0.000048 |
| init | 0.000033 |
| System lock | 0.000006 |
| optimizing | 0.000018 |
| statistics | 0.000018 |
| preparing | 0.000015 |
| Sorting result | 0.000006 |
| executing | 0.000328 |
| Sending data | 0.000016 |
| Creating sort index | 0.000081 |
| end | 0.000004 |
| query end | 0.000006 |
| closing tables | 0.000003 |
| removing tmp table | 0.000005 |
| closing tables | 0.000004 |
| freeing items | 0.000068 |
| cleaning up | 0.000017 |
+----------------------+----------+
其他查看方法:
mysql> show profile;
mysql> select * from information_schema.profiling;
mysql> select * from information_schema.profiling where query_id=6 or

mysql> show profile; #默认显示时间信息
mysql> show profile CPU,BLOCK IO; #(时间)加上 CPU,BLOCK IO 使用情况
mysql> show profile for query 6; #query_id=6的(时间)信息
mysql> show profile CPU for query 6; #query_id=6的cpu信息
mysql> show profile CPU limit 6; #前6个状态信息(前6行)
mysql> show profile CPU limit 6 offset 2;#第2行起前6个状态信息(前2~7行)

关闭跟踪:

set profiling = 0;
set profiling_history_size = 0;

---------------------
作者:薛定谔的DBA
来源:CSDN
原文:https://blog.csdn.net/kk185800961/article/details/57425258?utm_source=copy
版权声明:本文为博主原创文章,转载请附上博文链接!

MySQL PROFILE 跟踪语句各阶段性能开销的更多相关文章

  1. MySQL的SSL加密连接与性能开销

    本文转载自:http://www.innomysql.net/article/23959.html(只作转载, 不代表本站和博主同意文中观点或证实文中信息) Contents [hide] 1 前言 ...

  2. 老李分享:MySql的insert语句的性能优化方案

    老李分享:MySql的insert语句的性能优化方案   性能优化一直是测试人员比较感兴趣的内容,poptest在培训学员的时候也加大了性能测试调优的方面的内容,而性能优化需要经验的积累,经验的积累依 ...

  3. 高性能MySQL笔记 第6章 查询性能优化

    6.1 为什么查询速度会慢   查询的生命周期大致可按照顺序来看:从客户端,到服务器,然后在服务器上进行解析,生成执行计划,执行,并返回结果给客户端.其中“执行”可以认为是整个生命周期中最重要的阶段. ...

  4. mysql执行sql语句过程

    开发人员基本都知道,我们的数据存在数据库中(目前最多的是mysql和oracle,由于作者更擅长mysql,所以这里默认数据库为mysql),服务器通过sql语句将查询数据的请求传入到mysql数据库 ...

  5. mysql show profiles使用分析sql性能

    mysql show profiles使用分析sql性能 Show profiles是5.0.37之后添加的,要想使用此功能,要确保版本在5.0.37之后. 查看一下我的数据库版本 mysql> ...

  6. mysql 常用 sql 语句 - 快速查询

    Mysql 常用 sql 语句 - 快速查询 1.mysql 基础 1.1 mysql 交互         1.1.1 mysql 连接             mysql.exe -hPup    ...

  7. mysql的sql语句优化方法面试题总结

    mysql的sql语句优化方法面试题总结 不要写一些没有意义的查询,如需要生成一个空表结构: select col1,col2 into #t from t where 1=0 这类代码不会返回任何结 ...

  8. php面试专题---MySQL常用SQL语句优化

    php面试专题---MySQL常用SQL语句优化 一.总结 一句话总结: 原理,万变不离其宗:其实SQL语句优化的过程中,无非就是对mysql的执行计划理解,以及B+树索引的理解,其实只要我们理解执行 ...

  9. MYSQl 全表扫描以及查询性能

    MYSQl 全表扫描以及查询性能 -- 本文章仅用于学习,记录 一. Mysql在一些情况下全表检索比索引查询更快: 1.表格数据很少,使用全表检索会比使用索引检索更快.一般当表格总数据小于10行并且 ...

随机推荐

  1. Python 学习笔记01篇

    编程基础很零碎 看了路飞学城的讲解视频,整体课程列表排列很清晰,每个视频都在十几分钟到二十几分钟之间,适合零碎化的的学习 第一章和第二章的前半部分可以较轻松地入门

  2. Oracle 正则

    https://www.cnblogs.com/qmfsun/p/4467904.html 匹配汉字可以用Oracle 内置函数 unistr('\4e00') -unistr('\9fa5') 来定 ...

  3. Java读取excel数据保存入库

    Java开发读取excel表格数据入库保存: List<Map<String, Object>> list = null; String filePath = filePath ...

  4. STM32F401 外部中断误触发问题

    现象:调试STM32F411低功耗的时候,使用的PA1做个唤醒源,发现在没有触发EXTI的时候,MCU居然被唤醒. 原因:PA1配置成EXTI(上拉输入),经常被误触发 解决方式:将PA1配置成浮空输 ...

  5. 2018/12/22:centos中转换目录时/root的影响

    今天在将一个压缩包复制到/root下,并解压.从表面看我试在根目录下,但是就是不能进入生成的目录,提示no such file or diraction.最后我加上/root又好了,奇怪 编译环境:输 ...

  6. C/C++控制台接收不到鼠标消息-【解决办法】

    控制台编程中,使用了鼠标操作,遇到了控制台无法接收到鼠标消息的问题,可尝试一下办法解决 [win10系统] 在控制台标题栏右键-默认值-选项,将一下对勾取消 然后调用如下函数: HANDLE hIn ...

  7. Linux Simple Systemd Service Guide

    Simple Systemd Service Guide 主题 Systemd介绍 Systemd基本操作 怎样编写_service_.service文件 怎样部署service Systemd介绍 ...

  8. [Solution] 985. Sum of Even Numbers After Queries

    Difficulty: Easy Question We have an array A of integers, and an array queries of queries. For the i ...

  9. django RESTful设计方法

    1. 域名 应该尽量将API部署在专用域名之下. https://api.example.com 如果确定API很简单,不会有进一步扩展,可以考虑放在主域名下. https://example.org ...

  10. python note 09 初识函数

    1.函数 def my_len(): #自定义函数(相当于len) i = 0 for k in s: i += 1 print(i) print(my_len()) #输出None,因为没有返回值 ...