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

Mysql调优之profile的使用方法

mysql 搞代码 4年前 (2022-01-09) 36次浏览 已收录 0个评论
文章目录[隐藏]

本篇文章给大家带来的内容是关于Mysql调优之profile的使用方法,有一定的参考价值,有需要的朋友可以参考一下,希望对你有所帮助。

  1. 在我们做mysql性能分析的时候,最常用的有三种方式:

    (1)慢查询 (分析出现出问题的sql)
    (2)Explain (显示了mysql如何使用索引来处理select语句以及连接表。可以帮助选择更好的索引和写出更优化的查询语句)
    (3)Profile(查询到 SQL 会执行多少时间, 并看出 CPU/Memory 使用量, 执行过程中 Systemlock, Table lock 花多少时间等等.)

  2. 本章主要是对profile做简单的概述,用来对某一条sql语句进行性能分析。

  3. Profiling是从 mysql5.0.3版本以后才开放的。但是在mysql5.7之后,profile信息将逐渐被废弃,mysql推荐使用performance schema。

  4. profile此工具可用来查询SQL执行状态,System lock和Table lock 花多少时间等等,对定位一条语句的I/O消耗和CPU消耗 非常重要。(SQL 语句执行所消耗的最大两部分资源就是IO和CPU)

profile工具使用

  1. 查看自己的mysql版本:

    mysql> select version(); +------------+| version()  |+------------+| 5.6.35-log |+------------+
  2. 查看是否开启profile功能(profiling=on代表开启):

    mysql> show variables like '%profil%';+------------------------+-------+| Variable_name          | Value |+------------------------+-------+| have_profiling        | YES  || profiling              | OFF    || profiling_history_size | 15    |+------------------------+-------+
  3. 开启profile:

    mysql> set profile=1;
  4. 开启profile之后,执行要分析的sql语句:

    mysql> select t1.*,t2.action from pre_forum_thread as t1left join (select a.* from pre_forum_threadmod as a,(select tid,max(dateline) as dateline from pre_forum_threadmod group by tid) as bwhere a.tid=b.tid and a.dateline=b.dateline) as t2on t1.tid=t2.tidwhere t1.displayorder>=0 and t1.fid in (47,49) and t1.tid > 100318 and (t1.authorid =7683017 or t2.action<>'DWN' or t2.action is null )order by t1.dateline desc limit 20;
  5. 查看生成的profile信息:

    mysql> show profiles;+----------+------------+--------------------------------------------------------------------------------------------------------+| Query_ID | Duration  | Query                                                                                                  |+----------+------------+--------------------------------------------------------------------------------------------------------+|        1 | 1.37183777 | select t1.*,t2.action from pre_forum_thread as t1  ||        2 | 0.00078796 | show columns from `bbs`.`t2` ||        3 | 0.00150425 | show columns from `bbs`.`pre_forum_thread` |+----------+------------+--------------------------------------------------------------------------------------------------------+
  6. 获取指定的query语句的开销:

    mysql> show profile for query 2; +----------------------+----------+| Status              | Duration |+----------------------+----------+| starting            | 0.000147 || checking permissions | 0.000023 || Opening tables      | 0.000047 || init                | 0.000081 || System lock          | 0.000031 || optimizing          | 0.000034 || statistics          | 0.001650 || preparing            | 0<p>本文来源gao!daima.com搞$代!码#网#</p>.000046 || executing            | 0.000018 || Sending data        | 2.460588 || end                  | 0.000041 || query end            | 0.000019 || closing tables      | 0.000022 || freeing items        | 0.000055 || cleaning up          | 0.000085 |+----------------------+----------+

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

    喜欢 (0)
    [搞代码]
    分享 (0)
发表我的评论
取消评论

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

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

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