《Mysql必读mysql显示SQL语句执行时间的实例详解》要点:
本文介绍了Mysql必读mysql显示SQL语句执行时间的实例详解,希望对您有用。如果有疑问,可以联系我们。
本节内容:
显示SQL语句执行时间MYSQL教程
MySQL 的 SQL 语法调整主要使用 EXPLAIN,不过该命令无法获取详细的 Ram(Memory)/CPU 等使用量.MYSQL教程
于 MySQL 5.0.37 以上开始支持 MySQL Query Profiler, 可以查詢到此 SQL执行多长时间,并 並看出 CPU/Memory 使用量, 执行过程中 System lock, Table lock 花多少时间等.MYSQL教程
效能分析主要分下述三种:
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?MYSQL教程
Workload analysis - examines the server and who is logged on to determine the resource usage and activity of each.MYSQL教程
Ratio-based analysis - utilizes a number of rule-of-thumb ratios to gauge performance of a database, user connection, or piece of code.MYSQL教程
MySQL Query Profile 使用方法MYSQL教程
启动:
mysql> set profiling=1; # 此命令于 MySQL 会于 information_schema 的 database 建立一个 PROFILING 的 table 来记录.MYSQL教程
SQL profiles show
mysql> show profiles; # 从启动之后所有语法及使用时间, 含错误语法都会记录.
例如:MYSQL教程
1,查询所有花费时间加总
MYSQL教程
2,查询各执行阶段花费多少时间
MYSQL教程
3,查询各执行阶段花费的各种资源列表
MYSQL教程
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教程
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 |
+--------------------------------+----------+---------------+-------------------+MYSQL教程
4,其它属性列表
MYSQL教程
5,设定 Profiling 存的 Size:
MYSQL教程
关闭:
MYSQL教程
维易PHP培训学院每天发布《Mysql必读mysql显示SQL语句执行时间的实例详解》等实战技能,PHP、MYSQL、LINUX、APP、JS,CSS全面培养人才。