mysql profile使用(转)
mysql的sql语句优化都使用explain,但是这个没有办法知道详细的Memory/CPU等使用量
MySQL Query Profiler, 可以查询到此 SQL 语句会执行多少, 并看出 CPU/Memory 使用
量, 执行过程 System lock, Table lock 花多少时间等等.
mysql> show variables like 'profiling%';
+------------------------+-------+
| Variable_name | Value |
+------------------------+-------+
| profiling | OFF |
| profiling_history_size | 15 |
+------------------------+-------+
开启此功能
mysql>set profiling=1;
mysql> show variables like 'profiling%';
# 此命令会让mysql在 information_schema 的 database 建立一個 PROFILING 的
table 来记录.
+------------------------+-------+
| Variable_name | Value |
+------------------------+-------+
| profiling | ON |
| profiling_history_size | 15 |
+------------------------+-------+
profiling_history_size记录多少次查询
mysql> show profiles;
+----------+------------+------------------------------------+
| Query_ID | Duration | Query |
+----------+------------+------------------------------------+
| 1 | 0.00018100 | show variables like 'profiling%' |
| 2 | 0.00020400 | show variables like 'profiling%' |
| 3 | 0.00007800 | set profiling=1 |
| 4 | 0.00011000 | show variables like 'profiling%' |
| 5 | 0.00002400 | select count(1) from `mrhao_stats` |
| 6 | 1.52181400 | select count(*) from `mrhao_stats` |
| 7 | 0.00026900 | show variables like 'profiling%' |
mysql> show profile for query 6;
+--------------------------------+----------+
| Status | Duration |
+--------------------------------+----------+
| (initialization) | 0.000003 |
| checking query cache for query | 0.000042 |
| Opening tables | 0.00001 |
| System lock | 0.000004 |
| Table lock | 0.000025 |
| init | 0.000009 |
| optimizing | 0.000003 |
| statistics | 0.000007 |
| preparing | 0.000007 |
| executing | 0.000004 |
| Sending data | 1.521676 |
| end | 0.000007 |
| query end | 0.000003 |
| storing result in query cache | 0.000002 |
| freeing items | 0.000006 |
| closing tables | 0.000004 |
| logging slow query | 0.000002 |
+--------------------------------+----------+
17 rows in set (0.00 sec)
mysql> show profile cpu for query 6;
+--------------------------------+----------+----------+------------+
| Status | Duration | CPU_user | CPU_system |
+--------------------------------+----------+----------+------------+
| (initialization) | 0.000003 | 0 | 0 |
| checking query cache for query | 0.000042 | 0.001 | 0 |
| Opening tables | 0.00001 | 0 | 0 |
| System lock | 0.000004 | 0 | 0 |
| Table lock | 0.000025 | 0 | 0 |
| init | 0.000009 | 0 | 0 |
| optimizing | 0.000003 | 0 | 0 |
| statistics | 0.000007 | 0 | 0 |
| preparing | 0.000007 | 0 | 0 |
| executing | 0.000004 | 0 | 0 |
| Sending data | 1.521676 | 1.631752 | 0.036995 |
| end | 0.000007 | 0 | 0 |
| query end | 0.000003 | 0 | 0 |
| storing result in query cache | 0.000002 | 0 | 0 |
| freeing items | 0.000006 | 0 | 0 |
| closing tables | 0.000004 | 0 | 0 |
| logging slow query | 0.000002 | 0 | 0 |
+--------------------------------+----------+----------+------------+
17 rows in set (0.00 sec)
* ALL - displays all information
* BLOCK IO - displays counts for block input and output operations
* CONTEXT SWITCHES - displays counts for voluntary and involuntary
context switches
* IPC - displays counts for messages sent and received
* MEMORY - is not currently implemented
* PAGE FAULTS - displays counts for major and minor page faults
* SOURCE - displays the names of functions from the source code, together
with the name and line number of the file in which the function occurs
* SWAPS - displays swap counts
查询时间跟cpu的使用
mysql> select min(seq) seq,state,count(*) numb_ops,
round(sum(duration),5) sum_dur, round(avg(duration),5) avg_dur,
round(sum(cpu_user),5) sum_cpu, round(avg(cpu_user),5) avg_cpu
from information_schema.profiling
where query_id = 7
group by state
order by seq;
关闭此功能
mysql> set profiling=0;
mysql> show variables like 'profiling%';
+------------------------+-------+
| Variable_name | Value |
+------------------------+-------+
| profiling | OFF |
| profiling_history_size | 15 |
+------------------------+-------+
mysql profile使用(转)相关推荐
- mysql profile 查谒_MYSQL查询优化:profile功能
这里还需要注意一点就是,需要安装profile模块才能实现. 1.不过版本要在5.0.37之后.(SHOW PROFILES and SHOW PROFILE were added in MySQL ...
- mysql profile 不记录_mysql profile使用(转)
mysql的sql语句优化都使用explain,但是这个没有办法知道详细的Memory/CPU等使用量 MySQL Query Profiler, 可以查询到此 SQL 语句会执行多少, 并看出 CP ...
- mysql profile 调试sql_SQL Server profile使用技巧
介绍 经常会有人问profile工具该怎么使用?有没有方法获取性能差的sql的问题.自从转mysql我自己也差不多2年没有使用profile,忽然profile变得有点生疏不得不重新熟悉一下.这篇文章 ...
- mysql profile 导出_MySQL数据的导出和导入工具:mysqldump_MySQL
mysqldump 导出要用到MySQL的mysqldump工具,基本用法是: shell> mysqldump [OPTIONS] database [tables] 如果你不给定任何表,整个 ...
- mysql for 语句执行顺序_MySQL使用profile分析SQL语句执行过程
分析SQL执行带来的开销是优化SQL的重要手段.在MySQL数据库中,可以通过配置profiling参数来启用SQL剖析.该参数可以在全局和session级别来设置.对于全局级别则作用于整个MySQL ...
- MySQL性能分析工具profile使用教程
分析SQL执行带来的开销是优化SQL的重要手段.在MySQL数据库中,可以通过配置profiling参数来启用SQL剖析.该参数可以在全局和session级别来设置.对于全局级别则作用于整个MySQL ...
- MySQL数据库开发常见问题及几点优化!
从一下三个方面考虑: 库表设计 慢 SQL 问题 误操作.程序 bug 时怎么办 一.库表设计 1.1.引擎选择 在 MySQL5.1 中,引入了新的插件式存储引擎体系结构,允许将存储引擎加载到正在运 ...
- mysql数据库优化(二)
1.sql防止注入 https://www.cnblogs.com/sevck/p/6733702.html View Code 结果: C:\Users\ASUS\kuaigong3.6.5\lib ...
- 利用Flume将MySQL表数据准实时抽取到HDFS
转自:http://blog.csdn.net/wzy0623/article/details/73650053 一.为什么要用到Flume 在以前搭建HAWQ数据仓库实验环境时,我使用Sqoop抽取 ...
最新文章
- ES聚合底层机制-bucket深的话采用广度优先更好,而如果是年度统计还是深度优先好...
- python网络编程基础(线程与进程、并行与并发、同步与异步、阻塞与非阻塞、CPU密集型与IO密集型)...
- [YTU]_1998( C语言实验——删除指定字符)
- [codevs 1914] 运输问题
- C语言寻找错误是哪个快捷键,求大佬改正寻找一下错误,
- python方差特征选择_使用scikitlearn进行方差分析的特征选择和交叉验证
- Android学习点点滴滴之获取正在运行的进程
- java 对象地址_如何获取Java对象的地址?
- Linux学习笔记---使用MfgTool工具烧写官方系统(一)
- R语言如何并行处理[parallel package][向量化操作并行优化]
- webstorage html5,HTML5-WebStorageAPIs的简述
- HDU 5570:balls 期望。。。。。。。。。。。。。。。
- JavaScript:剖析ES6(1)--let和const
- c语言非标准输出电源适配器,五分钟了解设计模式(3)---适配器模式
- UE5 live-coding和build中version“1.2“ not support build failed解决方法
- 服务器c盘怎么删除临时文件,删除临时文件夹中临时文件的方法
- WeChat 微信公众号开发步骤
- Teigha绘制“月亮”形状
- note20220411
- 【趣味】一个将任意数字分解成 114514 构成的公式的工具
热门文章
- STM32工作笔记0062---定时器中断实验
- System学习笔记004---Windows系统中hosts文件的作用_Zookeeper在SpringBoot中报错需要配置一下这个文件
- 交?叉?验?证?(?分?类?器?性?能?)
- 杭电1861 游船出租
- 3d激光雷达开发(lidar使用)
- 随想录(动态库的特点)
- 随想录(cpu缓存、cache同步和乱序执行)
- 用汇编的眼光看C++ (之x86汇编)
- linux开机自动联网设置
- 使用Arduino和超声波传感器实现简单测距