mysql show profiles使用分析sql性能

Show profiles是5.0.37之后添加的,要想使用此功能,要确保版本在5.0.37之后。

查看一下我的数据库版本

mysql> Select  version();

+---------------------+

| version()           |

+---------------------+

| 5.0.82-community-nt |

+---------------------+

  www.2cto.com

1 row in set (0.00 sec)

版本是支持show profiles功能的。接下来进入mysql性能跟踪诊断的世界

查看是否打开了profiles功能,默认是关闭的

mysql> use test;

Database changed

mysql> show profiles;

Empty set (0.00 sec)

显示为空,说明profiles功能是关闭的。下面开启

mysql> set profiling=1;

Query OK, 0 rows affected (0.00 sec)

执行下面的查询

  www.2cto.com

mysql> explain select distinct player_idfrom task limit 20;

mysql> select distinct player_id from task ;

然后执行 show profiles

mysql> show profiles;

+----------+------------+------------------------------------------------------+

| Query_ID | Duration   | Query                                               |

+----------+------------+------------------------------------------------------+

|       1 | 0.00035225 | explain select distinct player_id from task limit 20 |

|       2 | 1.91772775 | select distinct player_id from task                  |

+----------+------------+------------------------------------------------------+

此时可以看到执行select distinct player_id from task 用了1.91772775秒的时间

根据query_id 查看某个查询的详细时间耗费

mysql> show profile for query 2;

  www.2cto.com

+----------------------+----------+

| Status               | Duration |

+----------------------+----------+

| starting             | 0.000052 |

| Opening tables       | 0.000009 |

| System lock          | 0.000003 |

| Table lock           | 0.000007 |

| init                 | 0.000013 |

| optimizing           | 0.000003 |

| statistics           | 0.000009 |

| preparing            | 0.000008 |

| Creating tmp table   | 0.000074 |

| executing            | 0.000002 |

| Copying to tmp table |1.916551 |

  www.2cto.com

| Sending data         | 0.000667 |

| end                  | 0.000004 |

| removing tmp table   | 0.000065 |

| end                  | 0.000002 |

| end                  | 0.000002 |

| query end            | 0.000003 |

| freeing items        | 0.000245 |

| closing tables       | 0.000006 |

| logging slow query   | 0.000002 |

| cleaning up          | 0.000003 |

+----------------------+----------+

可以看到红色字体部分耗费了大量时间,这是因为distinct查看会用到临时表

那么可不可以查看占用cpu、 io等信息呢

 mysql> show profile block io,cpu for query2;

+----------------------+----------+----------+------------+--------------+------

---------+

| Status               | Duration | CPU_user |CPU_system | Block_ops_in | Block

_ops_out |

+----------------------+----------+----------+------------+--------------+------

  www.2cto.com

---------+

| starting             | 0.000052 |     NULL |       NULL |         NULL |

   NULL |

| Opening tables       | 0.000009 |     NULL |       NULL |         NULL |

   NULL |

| System lock          | 0.000003 |     NULL |       NULL |         NULL |

   NULL |

| Table lock           | 0.000007 |     NULL |       NULL |         NULL |

   NULL |

| init                 | 0.000013 |     NULL |       NULL |         NULL |

   NULL |

| optimizing           | 0.000003 |     NULL |       NULL |         NULL |

   NULL |

| statistics           | 0.000009 |     NULL |       NULL |         NULL |

   NULL |  www.2cto.com

| preparing            | 0.000008 |     NULL |       NULL |        NULL |

   NULL |

| Creating tmp table   | 0.000074 |     NULL |       NULL |         NULL |

   NULL |

| executing            | 0.000002 |     NULL |       NULL |         NULL |

   NULL |

| Copying to tmp table | 1.916551 |     NULL |       NULL |        NULL |

   NULL |

| Sending data         | 0.000667 |     NULL |       NULL |         NULL |

   NULL |

| end                  | 0.000004 |     NULL |       NULL |         NULL |

   NULL |

| removing tmp table   | 0.000065 |     NULL |       NULL |         NULL |

   NULL |

| end                  | 0.000002 |     NULL |       NULL |         NULL |

   NULL |

| end                  | 0.000002 |     NULL |       NULL |         NULL |

   NULL |

| query end            | 0.000003 |     NULL |       NULL |         NULL |

   NULL |

| freeing items        | 0.000245 |     NULL |       NULL |         NULL |

   NULL |

| closing tables       | 0.000006 |     NULL |       NULL |         NULL |

   NULL |

  www.2cto.com

| logging slow query   | 0.000002 |     NULL |       NULL |         NULL |

   NULL |

| cleaning up          | 0.000003 |     NULL |       NULL |         NULL |

   NULL |

+----------------------+----------+----------+------------+--------------+------

另外还可以看到memory,swaps,context switches,source 等信息

具体信息可以参考http://dev.mysql.com/doc/refman/5.0/en/show-profiles.html

mysql show profiles使用分析sql性能的更多相关文章

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

    Show profiles是5.0.37之后添加的,要想使用此功能,要确保版本在5.0.37之后. 查看一下我的数据库版本 MySQL> Select  version(); +-------- ...

  2. 使用show profiles分析SQL性能

    如何查看执行SQL的耗时 使用show profiles分析sql性能. Show profiles是5.0.37之后添加的,要想使用此功能,要确保版本在5.0.37之后. 查看数据库版本 mysql ...

  3. 【MS SQL】通过执行计划来分析SQL性能

    原文:[MS SQL]通过执行计划来分析SQL性能 如何知道一句SQL语句的执行效率呢,只知道下面3种: 1.通过SQL语句执行时磁盘的活动量(IO)信息来分析:SET STATISTICS IO O ...

  4. mysql 分析3使用分析sql 性能 show profiles ;

    show variables like '%profiling%';    查看状态  查看时间去哪了``` set  profiling=1;// 打开 show profiles;  查看执行过的 ...

  5. MySQL高级篇 | 分析sql性能

    在应用的的开发过程中,由于初期数据量小,开发人员写 SQL 语句时更重视功能上的实现,但是当应用系统正式上线后,随着生产数据量的急剧增长,很多 SQL 语句开始逐渐显露出性能问题,对生产的影响也越来越 ...

  6. 使用Oracle执行计划分析SQL性能

    执行计划:一条查询语句在ORACLE中的执行过程或访问路径的描述.即就是对一个查询任务,做出一份怎样去完成任务的详细方案. 如果要分析某条SQL的性能问题,通常我们要先看SQL的执行计划,看看SQL的 ...

  7. MySQL字符集不一致导致查询SQL性能问题

    今天做了一个MySQL数据库中的SQL优化. 结论是关联字段字符集不同,导致索引不可用. 查询的SQL如下: select `Alias`.`Grade`, `Alias`.`id`, `Alias` ...

  8. MySQL进阶篇(01):基于多个维度,分析服务器性能

    本文源码:GitHub·点这里 || GitEE·点这里 一.服务器性能简介 1.性能定义 服务器性能优化是一项非常艰巨的任务,当然也是很难处理的问题,在写这篇文章的时候,特意请教下运维大佬,硬件工程 ...

  9. Oracle DB SQL 性能分析器

    • 确定使用SQL 性能分析器的优点 • 描述SQL 性能分析器工作流阶段 • 使用SQL 性能分析器确定数据库更改所带来的性能改进 SQL 性能分析器:概览 • 11g 的新增功能 • 目标用户:D ...

随机推荐

  1. 在另一个文本框显示input file选择的文件名字

    javascript 获取文件域 (type=file) 的完整路径一直是很麻烦的问题,问题主要出在一些浏览器基于安全性考虑而不能正常获取到文件域中选中图片的决对路径,尤其一些基于webkit的浏览器 ...

  2. java中final修饰符的使用

    1.final修饰符的用法: final可以修饰变量,被final修饰的变量被赋初始值之后,不能对它重新赋值. final可以修饰方法,被final修饰的方法不能被重写. final可以修饰类,被fi ...

  3. django的setting文件更换了位置需要进行的更改

    1. Pycharm --> 工具栏 --> Edit Configurations --> 修改 settings 文件 2. 项目文件夹下的wsgi.py 3. 项目文件夹下的m ...

  4. pyhton mechanize 学习笔记

    1:简单的使用 import mechanize # response = mechanize.urlopen("http://www.hao123.com/") request ...

  5. Plain Old Data (POD)

    Plain Old Data (POD) POD指的是这样一些数据类型:基本数据类型.指针.union.数组.构造函数是 trivial 的 struct 或者 class. POD用来表明C++中与 ...

  6. 转载---sql之left join、right join、inner join的区别

    原文地址:http://www.cnblogs.com/pcjim/articles/799302.html sql之left join.right join.inner join的区别 left j ...

  7. IIS7.0添加IP地址和域名限制

    IIS7.0默认安装是没有“IP地址和域名限制”功能的,需要我们自己选择安装 1.windows系统的添加方式 控制面板--程序与功能--启用或关闭windows功能--internat inform ...

  8. 前端读者 | 分分钟让你理解HTTPS

    本文来自@Keely袁庆玲:来源:https://juejin.im/post/5ad6ad575188255c272273c4 目前来看大多数网站都从HTTP转向HTTPS,不在支持HTTP,所以了 ...

  9. sublime text3中使用Emmet部分标签无法闭合

    转载自:http://geek100.com/2490/ 不过很早就发现br,input, img在sublime text中是没有闭合标签 / 的. 我一般都是手动补上的, 今天突然想起这个问题, ...

  10. HTTP 协议基本知识

    HTTP协议    7.1.什么是HTTP协议:        HTTP协议是用来规定浏览器客户端和服务器通信的方式 7.2.基本原则        基于请求响应模型        一次请求对应一次响 ...