MySQL PROFILE 跟踪语句各阶段性能开销
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 跟踪语句各阶段性能开销的更多相关文章
- MySQL的SSL加密连接与性能开销
本文转载自:http://www.innomysql.net/article/23959.html(只作转载, 不代表本站和博主同意文中观点或证实文中信息) Contents [hide] 1 前言 ...
- 老李分享:MySql的insert语句的性能优化方案
老李分享:MySql的insert语句的性能优化方案 性能优化一直是测试人员比较感兴趣的内容,poptest在培训学员的时候也加大了性能测试调优的方面的内容,而性能优化需要经验的积累,经验的积累依 ...
- 高性能MySQL笔记 第6章 查询性能优化
6.1 为什么查询速度会慢 查询的生命周期大致可按照顺序来看:从客户端,到服务器,然后在服务器上进行解析,生成执行计划,执行,并返回结果给客户端.其中“执行”可以认为是整个生命周期中最重要的阶段. ...
- mysql执行sql语句过程
开发人员基本都知道,我们的数据存在数据库中(目前最多的是mysql和oracle,由于作者更擅长mysql,所以这里默认数据库为mysql),服务器通过sql语句将查询数据的请求传入到mysql数据库 ...
- mysql show profiles使用分析sql性能
mysql show profiles使用分析sql性能 Show profiles是5.0.37之后添加的,要想使用此功能,要确保版本在5.0.37之后. 查看一下我的数据库版本 mysql> ...
- mysql 常用 sql 语句 - 快速查询
Mysql 常用 sql 语句 - 快速查询 1.mysql 基础 1.1 mysql 交互 1.1.1 mysql 连接 mysql.exe -hPup ...
- mysql的sql语句优化方法面试题总结
mysql的sql语句优化方法面试题总结 不要写一些没有意义的查询,如需要生成一个空表结构: select col1,col2 into #t from t where 1=0 这类代码不会返回任何结 ...
- php面试专题---MySQL常用SQL语句优化
php面试专题---MySQL常用SQL语句优化 一.总结 一句话总结: 原理,万变不离其宗:其实SQL语句优化的过程中,无非就是对mysql的执行计划理解,以及B+树索引的理解,其实只要我们理解执行 ...
- MYSQl 全表扫描以及查询性能
MYSQl 全表扫描以及查询性能 -- 本文章仅用于学习,记录 一. Mysql在一些情况下全表检索比索引查询更快: 1.表格数据很少,使用全表检索会比使用索引检索更快.一般当表格总数据小于10行并且 ...
随机推荐
- 关于Qrc文件的用法
在python文件xxx.py中调用资源文件,一般来说,需要将资源放在xxx.py的相同目录下:然而,当在xxx.py下建立一个统一目录/rec则需要建立xxx.qrc文件才能让xxx.py调用,调用 ...
- git 琐碎
git symbolic-ref --short HEAD 来获取对应 HEAD 的分支名 ➜ mis-gulf git:(mis-lk) ✗ git symbolic-ref --short HEA ...
- webstorm没有及时将改动保存到文件盘的问题
webpack经常监听不到webstorm的改动,即使手动ctrl+s了,导致无法触发编译,去google查了下,发现webstorm有一个“save write”的功能,见下图: 这选项的作用应该是 ...
- loadrunner 关联函数web_reg_save_param
当我们每次访问网站都需要提交从服务器获取的动态文本时就会需要用到关联函数,就好像每次乘坐火车票我们都需要用最新的火车票,如果用旧车票就不能做火车,如果我们采用了录制时的旧动态码如usersession ...
- java 将mysql中Blob类型转为字符串或数字
引入Blob类型貌似不行,不知道是版本问题还是java中的Blob类型为oracle,后来使用byte[]转换成功. public float byte2float(byte[] b) { if(b! ...
- 聊聊 HashMap
数据存储底层? 数据底层具体存储是一个Node<K,V> HashMap 是基于哈希来映射的,那当映射冲突时候怎么解决? 链地址,数组+链表 HashMap 什么时候扩容? 负载因子 lo ...
- 在同时满足if 和 else 条件的情况下,输出所需的内容。
请问划线处填什么内容,可以输出 "Hello World!"?if(__________){ printf("Hello ");}else{ pri ...
- python--第十五天总结(jquery)
空格:$('parent childchild')表示获取parent下的所有的childchild节点,所有的子孙. 大于号:$('parent > child')表示获取parent下的所有 ...
- 第二篇 Flask 中的 Render Redirect HttpResponse
第二篇 Flask 中的 Render Redirect HttpResponse 1.Flask中的HTTPResponse 在Flask 中的HttpResponse 在我们看来其实就是直接返 ...
- Mac 怎么通过自带终端连接linux服务器
简单来说,就两步骤 · 打开Mac终端,切换到root权限下 切换root权限: sudo -i ·通过ssh命令连接linux服务器 ssh root@127.0.0.1 root是账户名,@后面的 ...