登录  /  注册
Mysql使用profile分析sql开销的代码
不言
发布: 2019-03-13 14:15:57
转载
1490人浏览过

本篇文章给大家带来的内容是关于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开销的代码的详细内容,更多请关注php中文网其它相关文章!

相关标签:
来源:segmentfault网
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系admin@php.cn
热门教程
更多>
最新下载
更多>
网站特效
网站源码
网站素材
前端模板
关于我们 免责申明 意见反馈 讲师合作 广告合作 技术文章
php中文网:公益在线php培训,帮助PHP学习者快速成长!
关注服务号 技术交流群
PHP中文网订阅号
每天精选资源文章推送
PHP中文网APP
随时随地碎片化学习
PHP中文网抖音号
发现有趣的

Copyright 2014-2023 //m.sbmmt.com/ All Rights Reserved | 苏州跃动光标网络科技有限公司 | 苏ICP备2020058653号-1

 | 本站CDN由 数掘科技 提供

登录PHP中文网,和优秀的人一起学习!
全站2000+教程免费学