12-09
12-09
12-09
12-09
12-09
12-09
12-09
12-09
12-09
12-09
12-09
12-09
ADADADADAD
mysql数据库 时间:2024-11-26 22:16:58
作者:文/会员上传
12-09
12-09
12-09
12-09
12-09
12-09
12-09
12-09
12-09
12-09
12-09
12-09
SHOW PROFILE 和 SHOW PROFILES 语句显示 MySQL 数据库语句的资源消耗情况。需要注意的是:这两条命令均显示当前会话的SQL资源消耗情况,不能显示其他会话的资源消耗情况。--需
以下为本文的正文内容,内容仅供参考!本站为公益性网站,复制本文以及下载DOC文档全部免费。
SHOW PROFILE 和 SHOW PROFILES 语句显示 MySQL 数据库语句的资源消耗情况。
需要注意的是:这两条命令均显示当前会话的SQL资源消耗情况,不能显示其他会话的资源消耗情况。
--需要打开Profiling参数
mysql> show variables like 'profil%';
+------------------------+-------+
| Variable_name | Value |
+------------------------+-------+
| profiling | OFF|
| profiling_history_size | 15|
+------------------------+-------+
2 rows in set (0.10 sec)
mysql> set profiling = 1;
Query OK, 0 rows affected (0.00 sec)
mysql> show session variables like 'profil%';
+------------------------+-------+
| Variable_name | Value |
+------------------------+-------+
| profiling | ON|
| profiling_history_size | 15|
+------------------------+-------+
2 rows in set (0.00 sec)
SHOW PROFILES显示最近发送到MySQL服务器的语句。显示语句的条数由profiling_history_size参数设定,默认值是15,最大值是100,将参数的值设为0并不会关闭profiling功能。除了SHOW PROFILE 和 SHOW PROFILES,其他的语句都会显示在列表中。
SHOW PROFIL会显示一条语句的具体信息。如果没有指定FOR QUERY语句,输出结果会显示最后执行的语句。如果指定了FOR QUERY和语句编号,则会显示指定语句的信息。语句编号对应SHOW PROFILES显示结果中的Query_ID字段。LIMIT语句会限制输出的行数。默认,SHOW PROFILE语句只显示状态和运行时间这两个字段,状态字段和SHOW PROCESSLIST里面的状态字段相似。
--示例
mysql> select * from t9;
mysql> select * from t_arc1 limit 10;
mysql> show profiles;
+----------+------------+-------------------------------+
| Query_ID | Duration| Query |
+----------+------------+-------------------------------+
|1 | 0.00019375 | select * from t9 |
|2 | 0.00023150 | select * from t_arc1 limit 10 |
+----------+------------+-------------------------------+
2 rows in set (0.00 sec)
mysql> show profile for query 2;
+----------------------+----------+
| Status| Duration |
+----------------------+----------+
| starting | 0.000058 |
| checking permissions | 0.000005 |
| Opening tables| 0.000011 |
| System lock | 0.000006 |
| init | 0.000015 |
| optimizing| 0.000003 |
| statistics| 0.000011 |
| preparing| 0.000010 |
| executing| 0.000002 |
| Sending data | 0.000094 |
| end | 0.000003 |
| query end| 0.000003 |
| closing tables| 0.000003 |
| freeing items| 0.000007 |
| logging slow query| 0.000001 |
| cleaning up | 0.000002 |
+----------------------+----------+
16 rows in set (0.00 sec)
mysql> show profile cpu for query 2;
+----------------------+----------+----------+------------+
| Status| Duration | CPU_user | CPU_system |
+----------------------+----------+----------+------------+
| starting | 0.000058 | 0.000000 |0.000000 |
| checking permissions | 0.000005 | 0.000000 |0.000000 |
| Opening tables| 0.000011 | 0.000000 |0.000000 |
| System lock | 0.000006 | 0.000000 |0.000000 |
| init | 0.000015 | 0.000000 |0.000000 |
| optimizing| 0.000003 | 0.000000 |0.000000 |
| statistics| 0.000011 | 0.000000 |0.000000 |
| preparing| 0.000010 | 0.000000 |0.000000 |
| executing| 0.000002 | 0.000000 |0.000000 |
| Sending data | 0.000094 | 0.000000 |0.000000 |
| end | 0.000003 | 0.000000 |0.000000 |
| query end| 0.000003 | 0.000000 |0.000000 |
| closing tables| 0.000003 | 0.000000 |0.000000 |
| freeing items| 0.000007 | 0.000000 |0.000000 |
| logging slow query| 0.000001 | 0.000000 |0.000000 |
| cleaning up | 0.000002 | 0.000000 |0.000000 |
+----------------------+----------+----------+------------+
16 rows in set (0.00 sec)
--查看SQL解析执行过程中每个步骤对应的源码的文件、函数名以及具体的源文件行数
MariaDB [test]> show profile source for query 31\G
*************************** 1. row ***************************
Status: starting
Duration: 0.000034
Source_function: NULL
Source_file: NULL
Source_line: NULL
*************************** 2. row ***************************
Status: checking permissions
Duration: 0.000005
Source_function: check_access
Source_file: sql_parse.cc
Source_line: 6043
11-20
11-19
11-20
11-20
11-20
11-19
11-20
11-20
11-19
11-20
11-19
11-19
11-19
11-19
11-19
11-19