zoukankan      html  css  js  c++  java
  • mysql中profile用法

    MySQL5.0.37版本以上支持PROFILING调试功能,让您可以了解SQL语句消耗资源的详细信息。因为它需要调用系统的getrusage()函数,所以只是在Linux/Unix类平台上才能使用,而不能在Windows平台上使用。而且,PROFILING是针对处理进程(process)而不是线程(thread)的,服务器上的其他应用,可能会影响您的调试结果,因此,这个工具适合开发过程中的调试,如果要在生产环境中调试使用,则要注意它的局限性

    首先 通过命令打开profile功能:

    mysql> set profiling=1;
    Query OK, 0 rows affected (0.00 sec)

    现在想通过profile调试一条查询语句执行的时间

    然后 执行以下sql:

    mysql> select * from aa;
    +----+---------+
    | id | content |
    +----+---------+
    |  1 | NULL    |
    |  2 | aaa     |
    +----+---------+
    2 rows in set (0.00 sec)

    最后查询消耗:

    mysql> show profile;
    +----------------------+----------+
    | Status               | Duration |
    +----------------------+----------+
    | starting             | 0.000054 |
    | checking permissions | 0.000014 |
    | Opening tables       | 0.000361 |
    | System lock          | 0.000014 |
    | init                 | 0.000018 |
    | optimizing           | 0.000007 |
    | statistics           | 0.000015 |
    | preparing            | 0.000010 |
    | executing            | 0.000005 |
    | Sending data         | 0.000074 |
    | end                  | 0.000008 |
    | query end            | 0.000007 |
    | closing tables       | 0.000020 |
    | freeing items        | 0.000048 |
    | logging slow query   | 0.000006 |
    | cleaning up          | 0.000005 |
    +----------------------+----------+
    16 rows in set (0.00 sec)

    可以看到一条sql执行 需要经过这么多的过程 每一个过程需要执行多少时间 但是这个功能只能看到查询的消耗 如果我执行任何一条命令 我都要知道执行的时间

    可以使用命令

    mysql> show profiles;
    +----------+------------+--------------------+
    | Query_ID | Duration   | Query              |
    +----------+------------+--------------------+
    |        8 | 0.00028275 | select getrusage() |
    |        9 | 0.00015925 | SELECT DATABASE()  |
    |       10 | 0.00026875 | select getrusage() |
    |       11 | 0.00016550 | SELECT DATABASE()  |
    |       12 | 0.00066325 | select * from aa   |
    +----------+------------+--------------------+
    5 rows in set (0.00 sec)

    这里 可以设置这个profiles这个表的条数 通过命令 

    set profiling_history_size=5; 设置 如果超过五个 第一条被删除 以此类推

  • 相关阅读:
    TopShelf注册win10 服务
    win 10服务简单注册
    关于Win10 的服务注册
    泛型 Generic
    数据转换成字符串格式
    蛋白粉怎么吃
    6 ways to Sort Pandas Dataframe: Pandas Tutorial
    GET and POST requests using Python
    python中安装包出现Retrying, 国内pip源提示“not a trusted or secure host”解决
    Anaconda 4.7.5
  • 原文地址:https://www.cnblogs.com/liaomin416100569/p/9331258.html
Copyright © 2011-2022 走看看