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. jsp页面点击打印按钮调用系统 的打印功能

    <script language=javascript> function prt() { var btn_obj = document.getElementById("prin ...

  2. 【SQL】宿主语言接口

    一般情况下,SQL语句是嵌套在宿主语言(如C语言)中的.有两种嵌套方式: 1.调用层接口(CLI):提供一些库,库中的函数和方法实现SQL的调用 2.直接嵌套SQL:在代码中嵌套SQL语句,提交给预处 ...

  3. 一个关于Java 多线程问题的知识点

    这个程序运行结果会是什么? public class Main {static class ListAdd { private static List list = new ArrayList(); ...

  4. java.io.WriteAbortedException异常

    java.io.WriteAbortedException异常 未实现 public interface Serializable 接口的类将无法使其任何状态序列化或反序列化. 可序列化类的所有子类型 ...

  5. CF 1005B Delete from the Left 【模拟数组操作/正难则反】

    You are given two strings s and t. In a single move, you can choose any of two strings and delete th ...

  6. HDU 2567 寻梦(字符串,插入)

    #include<iostream> #include<stdio.h> #include<string.h> #include<cmath> usin ...

  7. Java中byte与(16进制)字符串的互相转换

    java中byte用二进制表示占用8位,而我们知道16进制的每个字符需要用4位二进制位来表示,所以我们就可以把每个byte转换成两个相应的16进制字符,即把byte的高4位和低4位分别转换成相应的16 ...

  8. ACM-ICPC 2018 沈阳赛区网络预赛 D. Made In Heaven(第k短路模板)

    求第k短路模板 先逆向求每个点到终点的距离,再用dij算法,不会超时(虽然还没搞明白为啥... #include<iostream> #include<cstdio> #inc ...

  9. websocket、文件上传

    支持情况: 浏览器实现了websocket的浏览器:Chrome Supported in version 4+ Firefox Supported in version 4+ Internet Ex ...

  10. intellij idea android错误: Missing styles. Is the correct theme chosen for this layout?

    Missing styles. Is the correct theme chosen for this layout? Use the Theme combo box above the layou ...