• 欢迎访问搞代码网站,推荐使用最新版火狐浏览器和Chrome浏览器访问本网站!
  • 如果您觉得本站非常有看点,那么赶紧使用Ctrl+D 收藏搞代码吧

Mysql使用profile分析sql开销的代码

mysql 搞代码 4年前 (2022-01-09) 15次浏览 已收录 0个评论

本篇文章给大家带来的内容是关于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                                                                  <i style="color:transparent">本文来源gaodai$ma#com搞$代*码*网(</i>                      |    +----------+------------+--------------------------------------------------------------------------------------------------------------------------+    分析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开销的代码的详细内容,更多请关注搞代码gaodaima其它相关文章!


搞代码网(gaodaima.com)提供的所有资源部分来自互联网,如果有侵犯您的版权或其他权益,请说明详细缘由并提供版权或权益证明然后发送到邮箱[email protected],我们会在看到邮件的第一时间内为您处理,或直接联系QQ:872152909。本网站采用BY-NC-SA协议进行授权
转载请注明原文链接:Mysql使用profile分析sql开销的代码
喜欢 (0)
[搞代码]
分享 (0)
发表我的评论
取消评论

表情 贴图 加粗 删除线 居中 斜体 签到

Hi,您需要填写昵称和邮箱!

  • 昵称 (必填)
  • 邮箱 (必填)
  • 网址