加入收藏 | 设为首页 | 会员中心 | 我要投稿 应用网_丽江站长网 (http://www.0888zz.com/)- 科技、建站、数据工具、云上网络、机器学习!
当前位置: 首页 > 站长学院 > MySql教程 > 正文

MySQL 5.5中SHOW PROFILE、SHOW PROFILES语句怎么用

发布时间:2022-01-12 08:30:02 所属栏目:MySql教程 来源:互联网
导读:这篇文章将为大家详细讲解有关MySQL 5.5中SHOW PROFILE、SHOW PROFILES语句怎么用,小编觉得挺实用的,因此分享给大家做个参考,希望大家阅读完这篇文章后可以有所收获。 SHOW PROFILE 和 SHOW PROFILES 语句显示 MySQL 数据库语句的资源消耗情况。 需要注
      这篇文章将为大家详细讲解有关MySQL 5.5中SHOW PROFILE、SHOW PROFILES语句怎么用,小编觉得挺实用的,因此分享给大家做个参考,希望大家阅读完这篇文章后可以有所收获。
 
     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 31G
*************************** 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
 
关于“MySQL 5.5中SHOW PROFILE、SHOW PROFILES语句怎么用”这篇文章就分享到这里了,希望以上内容可以对大家有一定的帮助,使各位可以学到更多知识,如果觉得文章不错,请把它分享出去让更多的人看到。

(编辑:应用网_丽江站长网)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    热点阅读