博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
MySQL 5.5 SHOW PROFILE、SHOW PROFILES语句介绍
阅读量:2498 次
发布时间:2019-05-11

本文共 3722 字,大约阅读时间需要 12 分钟。

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

来自 “ ITPUB博客 ” ,链接:http://blog.itpub.net/26506993/viewspace-2097692/,如需转载,请注明出处,否则将追究法律责任。

转载于:http://blog.itpub.net/26506993/viewspace-2097692/

你可能感兴趣的文章
flutter控件之RadioButton
查看>>
Android如何在一个线性布局里完美显示两个listview啊?
查看>>
TortoiseGit 使用教程
查看>>
SQL表连接查询(inner join、full join、left join、right join)
查看>>
DB2中循环日期跑数据
查看>>
工作笔记还是蛮有用
查看>>
servlet3.0 的新特性之二注解代替了web.xml配置文件
查看>>
python 内置方法
查看>>
python 编码格式
查看>>
python 算法中的--冒泡排序
查看>>
代码阅读
查看>>
【原创】在 Mac OS X 上打造舒服的开发环境(三)——利用 Parallel Desktop 安装 CentOS 7...
查看>>
How Flask Routing Works
查看>>
Python新式类和经典类的区别
查看>>
整数快速乘法/快速幂+矩阵快速幂+Strassen算法 (转)
查看>>
匿名内部类
查看>>
C#字符串处理--学习笔记
查看>>
ios 保存数据NSKeyedArchiver,NSUserDefaults,Write,SQLite
查看>>
设计模式之代理模式
查看>>
html5中audio支持音频格式
查看>>