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

查看一下我的数据库版本

MySQL> Select  version();

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

| version()           |

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

| 5.0.82-community-nt |

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

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)

执行下面的查询

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;

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

| 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 |

| 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 |

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

---------+

| 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 |

| 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 |

| 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性能

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

  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. [World Final 2016] Branch Assignment

    链接 PDF bzoj 先求出正置边和反置边时b+1到前b个点的最短路dis[0/1][x](x∈[1,b]), 令D[x]=dis[0][x]+dis[1][x] 然后分组后每个x对代价的贡献为D[ ...

  2. Hbase到Solr数据同步及Solr分离实战

    1. 起因 由于历史原因,公司的数据是持久化在HBase中,查询是通过Solr来实现,这这样的设计必然涉及到要把Hbase中的数据实时同步到Solr,但所有的服务都在一个同一个集群及每台机子都安装了很 ...

  3. tilestache + mbutil应用

    1. 安装pip. 我们同样需要在Python的官网上去下载,下载地址是: https://pypi.python.org/pypi/pip#downloads 2. 解压. 解压pip-9.0.1. ...

  4. jQuery首页更换背景皮肤

    昨天做了一个jQuery首页更换背景皮肤,感觉还是挺不错的,一共需要两个文件,一个是我们写的HTML文件,我们起名叫做index.html,一个是我们引入的jQuery文件,我们起名叫做jQuery. ...

  5. Mac下使用VScode进行C/C++开发

    1.安装 从VScode官网下载Mac系统适用的VScode安装包,下载完成后,将zip安装包解压到桌面即可. 2.插件安装 实现 C/Cpp 代码自动补全,函数跳转. 打开VScode后,按下组合键 ...

  6. Android网络编程系列之Volley总结

    前言 Volley的中文翻译为“齐射.并发”,是在2013年的Google大会上发布的一款Android平台网络通信库,具有网络请求的处理.小图片的异步加载和缓存等功能,能够帮助 Android AP ...

  7. selenium 校验文件下载成功

    转自: http://www.seleniumeasy.com/selenium-tutorials/verify-file-after-downloading-using-webdriver-jav ...

  8. PHP的CURL的POST/GET访问

    本文出至:新太潮流网络博客 /** * [curl以GET的方式访问] * @E-mial wuliqiang_aa@163.com * @TIME 2017-04-07 * @WEB http:// ...

  9. webservice安全性浅谈

    原文地址:http://www.cnblogs.com/chhuic/archive/2009/11/19/1606109.html 做项目时,经常会用到WebService来通讯,但WebServi ...

  10. Use Jupyter notebook on Fedora 28

    生产环境使用 Fedora 28, 并且需要搭建一个 Jupyter 的notebook 方便使用,所搭建的Jupyter 支持单人远程 密码访问 1. 安装 安装 Jupyter , 出错 [roo ...