mysql显示SQL语句执行所消耗的时间
来源:互联网 发布:数据库中省略为什么 编辑:程序博客网 时间:2024/05/17 06:23
mysql>set profiling=1;
MySQL中查看SQL的执行计划主要是使用explain来查看,但这个没有办法知道内存及CPU等使用情况,自MySQL 5.0.37以后,mysql提供MySQL Query Profile可以查询到SQL执行所花费的时间,例如SQL执行过程中的SYSTEM LOCK,TABLE LOCK等所花费的时间。
MySQL Query Profile主要功能:
- Bottleneck Analysis
- Workload Analysis
- Ratio-based analysis
MySQL Query Profile使用方法
开启:
mysql>set profiling=1;
查看SQL Profile
mysql>show profiles;mysql>show profiles;+----------+------------+--------------------------------------------+|Query_ID|Duration |Query |+----------+------------+--------------------------------------------+| 11|0.00006600|show global variables buffer || 12|0.00059900|show global variables like'%buffer%' || 15|0.00052900|show global variables like'%buffer%' || 16|0.00048700|show global variables like'%cache%' || 17|0.00032600|select versioin() || 18|0.00010300|select version() |+----------+------------+--------------------------------------------+
查询各SQL执行所花费的时间
mysql>showprofileforquery19;# Query ID=19+--------------------------------+----------+|Status |Duration|+--------------------------------+----------+|starting |0.000019||checking query cache for query|0.000009||checking privileges on cached |0.000005||sending cached result to client|0.000011||logging slow query |0.000002||cleaning up |0.000002|+--------------------------------+----------+6 rows in set(0.01sec)
mysql>SHOW PROFILE CPU FOR QUERY 2;+----------------------+----------+----------+------------+|Status |Duration|CPU_user|CPU_system|+----------------------+----------+----------+------------+|checking permissions|0.000040|0.000038| 0.000002||creating table |0.000056|0.000028| 0.000028||After create |0.011363|0.000217| 0.001571||query end |0.000375|0.000013| 0.000028||freeing items |0.000089|0.000010| 0.000014||logging slow query |0.000019|0.000009| 0.000010||cleaning up |0.000005|0.000003| 0.000002|+----------------------+----------+----------+------------+7 rows in set(0.00sec)
Syntax:SHOWPROFILE[type[,type]...] [FORQUERYn] [LIMITrow_count[OFFSEToffset]] type: ALL |BLOCKIO |CONTEXTSWITCHES |CPU |IPC |MEMORY |PAGEFAULTS |SOURCE |SWAPS ALL displays all information BLOCKIO displays counts for block input and output operations CONTEXTSWITCHES displays counts for voluntary and involuntary context switches CPU displays user and system CPU usage times IPC displays counts for messages sent and received MEMORY is not currently implemented PAGEFAULTSdisplayscountsformajorandminorpagefaults SOURCE displays the names off unctions from the source code,together with the name and line number of the file in which the function occurs SWAPS displays swap counts
设置profileing存储记录的size
mysql>showvariableslike'%profiling%';+------------------------+-------+|Variable_name |Value|+------------------------+-------+|have_profiling |YES ||profiling |OFF ||profiling_history_size|15 |+------------------------+-------+3rowsinset(0.00sec) mysql>
关闭profile
mysql>set profiling=0;
Profiling is enabled per session. When a session ends, its profiling
information is lost.
0 0
- mysql显示SQL语句执行所消耗的时间
- mysql显示SQL语句执行所消耗的时间
- 查询sql语句执行消耗的时间
- 如何查看django执行的sql语句及消耗时间
- php检查代码执行所消耗的时间
- php检查代码执行所消耗的时间
- sql显示sql语句的执行时间及cpu消耗
- 在sql*plus中显示语句执行所用的时间
- SQL查询执行某条SQL语句所花费的时间
- 追踪应用程序所执行的sql语句
- Sql server统计查询语句消耗时间
- SQL 统计查询语句消耗时间
- 测特定指令执行时所需消耗的时间及系统资源
- 三种记录 MySQL 所执行过的 SQL 语句的方法
- mysql版本不同所导致SQL语句执行错误的问题
- 测试SQL语句执行所用的时间
- 抓SQL执行语句时间的脚本
- 【转】SQL SERVER 查看SQL语句IO,时间,索引消耗
- 使用shell脚本自动更新动态域名
- 使用 DBMS_PARALLEL_EXECUTE 更新大表
- 二叉树——建数字树,知先序、中序,输出后序
- java实现上传图片进行切割
- 每日一记:分数规划
- mysql显示SQL语句执行所消耗的时间
- 携程移动网站优化实践
- 组合模式理解Cocosd-x游戏引擎之addChild函数
- 简单usb驱动代码记录
- linux(Centos)上memcacheq成功安装及使用
- 最后我就拿着加多宝喝着走了…
- Unity IOC注入详细配置(MVC,WebApi)
- Android高性能编程注意事项
- 窗口创建类