mysql> help profiles;
Name: 'SHOW PROFILES'
Description:
Syntax:
SHOW PROFILE [type [, type] ... ]
[FOR QUERY n]
[LIMIT row_count [OFFSET offset]]
type:
ALL
| BLOCK IO
| CONTEXT SWITCHES
| CPU
| IPC
| MEMORY
| PAGE FAULTS
| SOURCE
| SWAPS
The SHOW PROFILES and SHOW PROFILE statements display profiling
information that indicates resource usage for statements executed
during the course of the current session.
Profiling is controlled by the profiling session variable, which has a
default value of 0 (OFF). Profiling is enabled by setting profiling to
1 or ON:
查看系统对该参数的设置
mysql> show variables like '%profili%';
+------------------------+-------+
| Variable_name | Value |
+------------------------+-------+
| have_profiling | YES |
| profiling | OFF |
| profiling_history_size | 15 |
+------------------------+-------+
3 rows in set (0.01 sec)
mysql>
可以看到默认是OFF状态,存储的大小为15条Query 然后开启该参数
mysql> set profiling=1;
Query OK, 0 rows affected (0.01 sec)
mysql> show variables like '%profili%';
+------------------------+-------+
| Variable_name | Value |
+------------------------+-------+
| have_profiling | YES |
| profiling | ON |
| profiling_history_size | 15 |
+------------------------+-------+
3 rows in set (0.00 sec)
mysql>
开始执行需要测试的SQL语句,MySQL数据库将会记录想关的调试信息
mysql> select * from mysql.user;
mysql> show profile; 可以看到刚才执行的这条Query的资源消耗
+----------------------+----------+
| Status | Duration |
+----------------------+----------+
| starting | 0.000694 |
| checking permissions | 0.000044 |
| Opening tables | 0.000223 |
| System lock | 0.000127 |
| init | 0.000238 |
| optimizing | 0.000035 |
| statistics | 0.000045 |
| preparing | 0.000022 |
| executing | 0.000013 |
| Sending data | 0.000418 |
| end | 0.000020 |
| query end | 0.000008 |
| closing tables | 0.000227 |
| freeing items | 0.001550 |
| logging slow query | 0.000012 |
| cleaning up | 0.000017 |
+----------------------+----------+
16 rows in set (0.01 sec)
mysql>