查看MySQL语法详细执行时间与CPU/记忆体使用量: MySQL Query Profiler

MySQL的SQL语法调整主要都是使用EXPLAIN,但是这个并没办法知道详细的Ram(Memory)/CPU等使用量.于MySQL 5.0.37以上开始支援MySQL Query Profiler,可以查询到此SQL会执行多少时间,并看出CPU/Memory使用量,执行过程中System lock, Table lock花多少时间等等.

MySQL Query Profile详细介绍可见: Using the New MySQL Query Profiler (2007.04.05发表)效能分析主要分下述三种(转载自上篇):

• Bottleneck analysis - focuses on answering the questions: What is my database server waiting on; what is a user connection waiting on; what is a piece of SQL code waiting on?

• Workload analysis - examines the server and who is logged on to determine the resource usage and activity of each.

• Ratio-based analysis - utilizes a number of rule-of-thumb ratios to gauge performance of a database, user connection, or piece of code.

MySQL Query Profile使用方法启动• mysql> set profiling=1;#此命令于MySQL会于information_schema的database建立一个PROFILING的table来纪录.

SQL profiles show

• mysql> show profiles; #从启动之后所有语法及使用时间,含错误语法都会纪录.

• ex: (root@localhost) [test]> show profiles; #注意Query_ID,下面执行时间统计等,都是依Query_ID在纪录• +----------+------------+------------------------ ---+

• | Query_ID | Duration | Query |

• +----------+------------+------------------------ ---+

• | 1 | 0.00090400 | show profile for query 1 |

• | 2 | 0.00008700 | select * from users |

• | 3 | 0.00183800 | show tables |

• | 4 | 0.00027600 | mysql> show profiles |

• +----------+------------+------------------------ ---+查询所有花费时间加总• mysql> select sum(duration) from information_schema.profiling where query_id=1; # Query ID = 1

• +---------------+

• | sum(duration) |

• +---------------+

• | 0.000447 |

• +---------------+查询各执行阶段花费多少时间• mysql> show profile for query 1; # Query ID = 1

• +--------------------+------------+

• | Status | Duration |

• +--------------------+------------+

• | (initialization) | 0.00006300 |

• | Opening tables | 0.00001400 |

• | System lock | 0.00000600 |

• | Table lock | 0.00001000 |

• | init | 0.00002200 |

• | optimizing | 0.00001100 |

• | statistics | 0.00009300 |

• | preparing | 0.00001700 |

• | executing | 0.00000700 |

• | Sending data | 0.00016800 |

• | end | 0.00000700 |

• | query end | 0.00000500 |

• | freeing items | 0.00001200 |

• | closing tables | 0.00000800 |

• | logging slow query | 0.00000400 |

• +--------------------+------------+查询各执行阶段花费的各种资源列表• mysql> show profile cpu for query 1; # Query ID = 1

• +--------------------------------+----------+---- ------+------------+

• | Status | Duration | CPU_user | CPU_system |

• +--------------------------------+----------+---- ------+------------+

• | (initialization) | 0.000007 | 0 | 0 |

• | checking query cache for query | 0.000071 | 0 | 0 |

• | Opening tables | 0.000024 | 0 | 0 |

• | System lock | 0.000014 | 0 | 0 |

• | Table lock | 0.000055 | 0.001 | 0 |

• | init | 0.000036 | 0 | 0 |

• | optimizing | 0.000013 | 0 | 0 |

• | statistics | 0.000021 | 0 | 0 |

• | preparing | 0.00002 | 0 | 0 |

• | executing | 0.00001 | 0 | 0 |

• | Sending data | 0.015072 | 0.011998 | 0 |

• | end | 0.000021 | 0 | 0 |

• | query end | 0.000011 | 0 | 0 |

• | storing result in query cache | 0.00001 | 0 | 0 |

• | freeing items | 0.000018 | 0 | 0 |

• | closing tables | 0.000019 | 0 | 0 |

• | logging slow query | 0.000009 | 0 | 0 |

• +--------------------------------+----------+---- ------+------------+

• mysql> show profile IPC for query 1;

• +--------------------------------+----------+---- -----------+-------------------+

• | Status | Duration | Messages_sent | Messages_received |

• +--------------------------------+----------+---- -----------+-------------------+

• | (initialization) | 0.000007 | 0 | 0 |

• | checking query cache for query | 0.000071 | 0 | 0 |

• | Opening tables | 0.000024 | 0 | 0 |

• | System lock | 0.000014 | 0 | 0 |

• | Table lock | 0.000055 | 0 | 0 |

• | init | 0.000036 | 0 | 0 |

• | optimizing | 0.000013 | 0 | 0 |

• | statistics | 0.000021 | 0 | 0 |

• | preparing | 0.00002 | 0 | 0 |

• | executing | 0.00001 | 0 | 0 |

• | Sending data | 0.015072 | 0 | 0 |

• | end | 0.000021 | 0 | 0 |

• | query end | 0.000011 | 0 | 0 |

• | storing result in query cache | 0.00001 | 0 | 0 |

• | freeing items | 0.000018 | 0 | 0 |

• | closing tables | 0.000019 | 0 | 0 |

• | logging slow query | 0.000009 | 0 | 0 |

• +--------------------------------+----------+---- -----------+-------------------+其它属性列表• ALL - displays all information

• BLOCK IO - displays counts for block input and output operations

• CONTEXT SWITCHES - displays counts for voluntary and involuntary context switches

• IPC - displays counts for messages sent and received

• MEMORY - is not currently implemented

• PAGE FAULTS - displays counts for major and minor page faults

• SOURCE - displays the names of functions from the source code, together with the name and line number of the file in which the function occurs

• SWAPS - displays swap counts设定Profiling存的Size

• mysql> show variables where variable_name='profiling_history_size'; #预设是15关闭• mysql> set profiling=0;

mysql query profiler_MySQL Query Profiler相关推荐

  1. python3 mysql错误 pymysql.err.OperationalError: (2013, 'Lost connection to MySQL server during query')

    pymysql错误: pymysql.err.OperationalError: (2013, 'Lost connection to MySQL server during query') pymy ...

  2. Procedure execution failed 2013 - Lost connection to MySQL server during query

    1 错误描写叙述 Procedure execution failed 2013 - Lost connection to MySQL server during query 2 错误原因 由错误描写 ...

  3. android+mysql+server+error_Lost connection to MySQL server during query错误 | 学步园

    关于 Lost connection to MySQL server during query 错误2007年04月11日 星期三 00:56晚上在虚拟机上继续玩 Delphi for PHP,想试试 ...

  4. mysql优化之query优化

    主要概述:在 MySQL 中有一个专门负责优化 SELECT 语句的优化器模块,这就是我们本节将要重点分析的 MySQL Optimizer,其主要的功能就是通过计算分析系统中收集的各种统计信息,为客 ...

  5. MySQL Workbench出现:Error Code: 2013. Lost connection to MySQL server during query的问题解决

    MySQL Workbench出现:Error Code: 2013. Lost connection to MySQL server during query的问题解决 参考文章: (1)MySQL ...

  6. Lost connection to MySQL server during query的几种可能分析

    在使用navicat导出查询结果时,发现一段时间后就断开连接了,报错:[Msg] [Exp] 2013 - Lost connection to MySQL server during query 开 ...

  7. 解决Lost connection to MySQL server during query错误方法

    昨天使用Navicat for MySQL导入MySQL数据库的时候,出现了一个严重的错误,Lost connection to MySQL server during query,字面意思就是在查询 ...

  8. 解决: Error Code: 2013. Lost connection to MySQL server during query

    执行SQL语句: update  table_C, table_A  set table_C.colC = table_A.colA where table_A.anotherId= table_C. ...

  9. MySQL Packet for query is too large (xxx > xxx)...by setting the ‘max_allowed_packet‘ variable.的解决办法

    问题概述 关于这个问题,博主是在项目上线生产运行的过程中遇到的,在一次运营部门的同事通知,系统功能操作出现异常,博主随即对问题展开排查和处理,通过后台日志发现,事务提交失败 " Could ...

最新文章

  1. rabbitmq系列问题解决:406, “PRECONDITION_FAILED - inequivalent arg ‘durable‘
  2. flutter_web 实战之文章列表与详情
  3. POJ 2230 DFS
  4. 秒杀系统设计架构与实现
  5. 易语言 mysql查询 中文乱码_大佬们E语言连接MYSQL输出中文乱码怎么破
  6. Spark SQL(五)之数据加载与存储
  7. LwIP应用开发笔记之八:LwIP无操作系统HTTP客户端
  8. QTextEdit显示中文乱码解决,中文GB2312转Unicode,QString、QByteArray 转换,16进制显示,toUtf8与toLocal8Bit区别
  9. 云知声今年要量产三款芯片,还公布了多模态AI芯片规划
  10. 《『若水新闻』客户端开发教程》——11.代码编码(3)
  11. Python 学习随笔
  12. android实现 5.0 6.0手机自动接听电话功能
  13. xpath的常见操作
  14. Mac下移动硬盘的使用
  15. DDoS 报告攻击类型占比
  16. 用 Python 分析《红楼梦》(2)
  17. 第六届世界互联网大会乌镇峰会简评
  18. 开发手札:Unity与Android交互(Unity2019+)
  19. android 2.3 刷机,【MIUI DFY】【Android 2.3.4】 刷机教程.doc
  20. Operator SDK

热门文章

  1. SolarWinds与安稳特加强合作关系,携手助力中国IT专业人士应对挑战
  2. 声网 Agora Share:从天到秒级效率提升,一切都为服务好 15 万+应用
  3. 微信潜规则:月薪过万的90后,过年都在看什么?
  4. 花了 4 天,破解 UNIX 联合创始人 39 年前的密码!
  5. 为什么要追求“极简”代码?
  6. 最早的算法可追溯到三千年前,“所谓的 AI 并非源自先进的技术”!
  7. 除了敲代码,程序员还需要哪些必备技能?
  8. 为防 Android 碎片化?Google 强迫开发者使用自有开发工具!
  9. 是谁榨干了 Android 设备的电量和流量?!| 极客头条
  10. 2018 腾讯功能游戏开发者赛事火热开启