Mysql如何使用profile分析sql开销

发布时间:2020-10-19 17:36:17 作者:小新
来源:亿速云 阅读:152

小编给大家分享一下Mysql如何使用profile分析sql开销,希望大家阅读完这篇文章后大所收获,下面让我们一起去探讨吧!

Mysql使用profile分析sql开销

1.使用之前先查看当前数据库的版本信息,低版本无法使用.
    show version();  或者 show variables like '%version%'
2.查看profiling
    show variables like '%profil%'    ;

    result:
        +------------------------+-------+  
        | Variable_name          | Value |  
        +------------------------+-------+  
        | have_profiling         | YES   |   --只读变量,用于控制是否由系统变量开启或禁用profiling  
        | profiling              | OFF   |   --开启SQL语句剖析功能  
        | profiling_history_size | 15    |   --设置保留profiling的数目,缺省为15,范围为0至100,为0时将禁用p

    show profiles; 查看是否开启,效果同上.
3.查看使用说明 
    help profile;
4.开启profile
    set profiling=1; 赋值时候不要有多余的空格.
5.运行sql,查看对应的profile
    select * from test ;
    show profiles;            

    result:
    +----------+------------+--------------------------------------------------------------------------------------------------------------------------+
    | Query_ID | Duration   | Query                                                                                                                    |
    +----------+------------+--------------------------------------------------------------------------------------------------------------------------+
    |       28 | 0.00033575 | select * from test                                                                                        |
    +----------+------------+--------------------------------------------------------------------------------------------------------------------------+

    分析sql性能,分析的时候可以加上对应的开销字段
    show profile [cpu,io][all] for query 28 ;

    show profile for query 28 ;

    +----------------------+----------+
    | Status               | Duration |
    +----------------------+----------+
    | starting             | 5.7E-5   |
    | checking permissions | 7E-6     |
    | Opening tables       | 1.7E-5   |
    | init                 | 2.3E-5   |
    | System lock          | 8E-6     |
    | optimizing           | 5E-6     |
    | statistics           | 1.1E-5   |
    | preparing            | 9E-6     |
    | executing            | 3E-6     |
    | Sending data         | 8.8E-5   |
    | end                  | 5E-6     |
    | query end            | 6E-6     |
    | closing tables       | 5E-6     |
    | freeing items        | 7.8E-5   |
    | cleaning up          | 1.5E-5   |
    +----------------------+----------+
6.关闭
    set profiling=off;

看完了这篇文章,相信你对Mysql如何使用profile分析sql开销有了一定的了解,想了解更多相关知识,欢迎关注亿速云行业资讯频道,感谢各位的阅读!

推荐阅读:
  1. sql server性能调优 I/O开销的示例分析
  2. profile怎么在mysql中使用

免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:is@yisu.com进行举报,并提供相关证据,一经查实,将立刻删除涉嫌侵权内容。

mysql

上一篇:手札--mongo建索引

下一篇:python如何使用关键字定义类

相关阅读

您好,登录后才能下订单哦!

密码登录
登录注册
其他方式登录
点击 登录注册 即表示同意《亿速云用户服务条款》