Mysql中Profiling之性能分析

Mysql中Profiling之性能分析MySQL5 0 37 版本以上支持了 Profiling 官方手册 此工具可用来查询 SQL 会执行多少时间 Systemlock 和 Tablelock 花多少时间等等 对定位一条语句的 I O 消耗和 CPU 消耗非常重要 从启动 profile 之后的所有查询包括错误的语句都会记录 关闭会话或者 setprofiling 0 就关闭了 开启 profilingmys gt se

MySQL5.0.37版本以上支持了Profiling – 官方手册。此工具可用来查询SQL 会执行多少时间,System lock和Table lock 花多少时间等等,对定位一条语句的I/O消耗和CPU消耗 非常重要。

从启动profile之后的所有查询包括错误的语句都会记录。
关闭会话或者set profiling=0 就关闭了。
# 开启profiling
mysql> set profiling=1;
mysql> select * from user limit 1;
mysql> select count(*) from user group by sexal;
# 查看这些语句的profile
mysql> show profiles;
+————–+—————-+————————————————————–+
| Query_ID | Duration     | Query                                                                      |
+————–+—————-+————————————————————–+
|        1        | 0.00013200   | SELECT DATABASE()                                               |
|        2        | 0.00044100   | select * from user limit 2                                      |
|        3        | 1.   | select nick,count(*) from user group by online|
+————–+—————-+————————————————————–+
查看具体一条(Query_ID=3 这一条)语句的profiles,包括CPU和柱塞I/O的情况
mysql> show profile cpu,block io for query 3;
+———————-+———-+———-+————+————–+—————+
| Status               | Duration | CPU_user | CPU_system | Block_ops_in | Block_ops_out |
+———————-+———-+———-+————+————–+—————+
| starting             | 0.000057 | 0.000000 |   0.000000 |            0 |             0 |
| Opening tables       | 0.000014 | 0.000000 |   0.000000 |            0 |             0 |
| System lock          | 0.000006 | 0.000000 |   0.000000 |            0 |             0 |
| Table lock           | 0.000009 | 0.000000 |   0.000000 |            0 |             0 |
| init                 | 0.000021 | 0.000000 |   0.000000 |            0 |             0 |
| optimizing           | 0.000006 | 0.000000 |   0.000000 |            0 |             0 |
| statistics           | 0.000011 | 0.000000 |   0.000000 |            0 |             0 |
| preparing            | 0.000010 | 0.000000 |   0.000000 |            0 |             0 |
| Creating tmp table   | 0.000039 | 0.000000 |   0.000000 |            0 |             0 |
| executing            | 0.000005 | 0.000000 |   0.000000 |            0 |             0 |
| Copying to tmp table | 1. | 1.030785 |   0. |          127 |           127 |
| Sorting result       | 0.000015 | 0.000000 |   0.000000 |            0 |             0 |
| Sending data         | 0.000015 | 0.000000 |   0.000000 |            0 |             0 |
| end                  | 0.000005 | 0.000000 |   0.000000 |            0 |             0 |
| removing tmp table   | 0.000008 | 0.000000 |   0.000000 |            0 |             0 |
| end                  | 0.000005 | 0.000000 |   0.000000 |            0 |             0 |
| query end            | 0.000004 | 0.000000 |   0.000000 |            0 |             0 |
| freeing items        | 0.000025 | 0.000000 |   0.000000 |            0 |             0 |
| logging slow query   | 0.000004 | 0.000000 |   0.000000 |            0 |             0 |
| cleaning up          | 0.000005 | 0.000000 |   0.000000 |            0 |             0 |
+———————-+———-+———-+————+————–+—————+
上面就获得了一条语句的CPU和Block IO消耗,对定位瓶颈很方便,其余的一些信息,可以用语句:“Show profile * for query 3”来获取
 
另外附上profiling 的学习质料
profiling 基础
http://www.xaprb.com/blog/2006/10/12/how-to-profile-a-query-in-mysql/
http://www.xaprb.com/blog/2006/10/15/a-case-study-in-profiling-queries-in-mysql/
http://www.xaprb.com/blog/2006/10/17/mysql-profiling-case-study-part-2/
profiling 进阶
http://www.mysqlperformanceblog.com/2009/01/19/profiling-mysql-stored-routines/
http://www.mysqlperformanceblog.com/2008/05/18/wanted-better-memory-profiling-for-mysql/
maatkit–perldoc mk-query-profiler
profiling高级
http://dev.mysql.com/tech-resources/articles/pro-mysql-ch6. html
http://dev. mysql .com/tech-resources/articles/using-new-query-profiler.html
profiling骨灰级
http://www.scribd.com/doc//DTrace-and-MySQL-Presentation
http://forge.mysql.com/wiki/Using_DTrace_with_MySQL

http://wikis.sun.com/display/BluePrints/Optimizing+MySQL+Database+Application+Performan

from: http://www.2cto.com/database/201202/118611.html




























































版权声明:本文内容由互联网用户自发贡献,该文观点仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请联系我们举报,一经查实,本站将立刻删除。

发布者:全栈程序员-站长,转载请注明出处:https://javaforall.net/214779.html原文链接:https://javaforall.net

(0)
上一篇 2026年3月18日 下午3:28
下一篇 2026年3月18日 下午3:28


相关推荐

  • java adt入门教程_Android基础入门教程目录

    java adt入门教程_Android基础入门教程目录第一章:环境搭建与开发相关(已完结10/10)https://blog.csdn.net/coder_pig/article/details/50000773Android基础入门教程——1.1背景相关与系统架构分析Android基础入门教程——1.2开发环境搭建Android基础入门教程——1.2.1使用Eclipse+ADT+SDK开发AndroidAPPAndroid基础入…

    2022年5月27日
    37
  • struts2的拦截器(4):通过继承AbstractInterceptor抽象类定义自己的拦截器

    struts2的拦截器(4):通过继承AbstractInterceptor抽象类定义自己的拦截器抽象类AbstractInterceptor实现了Interceptor接口,提供了init和destroy方法的空实现。如果我们的拦截器不需要打开资源,则可以无需实现这两个方法。可见通过继承AbstractInterceptor抽象类来实现自定义拦截器会更简单。将上篇文章中的SimpleInterceptor.java改为如下实现,其余所有代码一律不变:publicclassSim

    2022年5月14日
    35
  • Kubernetes各版本对应支持的docker版本列表

    Kubernetes各版本对应支持的docker版本列表Kubernetes主要做Docker的容器化管理,总结一下如何查看k8s对应支持的docker版本的方法。在GitHub可以查看所有Kubernetets版本信息:https://github.com/kubernetes/kubernetes/releases截止2019.08.09最新的版本支持信息:Kubernetes1.15.2–>Docker版本1.13…

    2025年6月26日
    4
  • java中如何进行异常处理_java检查时异常

    java中如何进行异常处理_java检查时异常运行时异常是Java编程语言所有异常的父类,这些异常在发生时会崩溃或崩溃,可能会破坏程序或应用程序。与不被视为运行时异常的异常不同,永远不会检查运行时异常。“运行时异常”通常显示程序员的错误,而不是预期程序要处理的条件。当无法发生的情况时,也会使用运行时异常。应该注意的是,当程序内存不足时,将引发程序错误,而不是将其显示为运行时异常。最常见的运行时异常为NullPointerException,A…

    2022年9月29日
    5
  • Ubuntu16.04安装ros_u盘安装双系统

    Ubuntu16.04安装ros_u盘安装双系统一、win10下安装Ubuntu16.04双系统1、制作系统U盘下载Ubuntu16.04我们首先去Ubuntu官网下一个Ubuntu16.04的iso镜像文件。

    2025年9月16日
    6
  • 合肥走出的语音智能王者,又把大模型推到国内顶流

    合肥走出的语音智能王者,又把大模型推到国内顶流

    2026年3月14日
    2

发表回复

您的邮箱地址不会被公开。 必填项已用 * 标注

关注全栈程序员社区公众号