三十六、【进阶】show profiles分析

1、profiles

(1)详情

可以帮助清楚的展现,每一条SQL语句的执行耗时,以及时间都耗费到哪里去了

(2)基础语句

2、查看是否支持profiles

mysql> select @@have_profiling;
+------------------+
| @@have_profiling |
+------------------+
| YES              |
+------------------+
1 row in set, 1 warning (0.00 sec)

3、查询profiles是否打开

默认情况下,MySQL数据库的profiles是关闭的,我们需要手动将其打开

(1)查询是否打开

select @@profiling;
mysql> select @@profiling;
+-------------+
| @@profiling |
+-------------+
|           0 |
+-------------+
1 row in set, 1 warning (0.00 sec)

(2)打开profiles

通过set语句,将profiling参数设置为1,即开启

mysql> set profiling =1;
Query OK, 0 rows affected, 1 warning (0.01 sec)

mysql> select @@profiling;
+-------------+
| @@profiling |
+-------------+
|           1 |
+-------------+
1 row in set, 1 warning (0.00 sec)

4、使用show profiles;语句

(1)查询语句的执行时间

show profiles;
mysql> show profiles;
+----------+------------+--------------------+
| Query_ID | Duration   | Query              |
+----------+------------+--------------------+
|        1 | 0.00041325 | select @@profiling |
|        2 | 0.00017100 | show tables        |
|        3 | 0.00032850 | SELECT DATABASE()  |
|        4 | 0.00130175 | show databases     |
|        5 | 0.00325000 | show tables        |
|        6 | 0.00115725 | show tables        |
|        7 | 0.00250400 | select * from stu  |
+----------+------------+--------------------+
7 rows in set, 1 warning (0.00 sec)

(2)查询某一条语句在各个阶段的耗时

show profiles for query 第几条语句;
mysql> show profile for query 5;
+--------------------------------+----------+
| Status                         | Duration |
+--------------------------------+----------+
| starting                       | 0.000044 |
| Executing hook on transaction  | 0.000005 |
| starting                       | 0.000018 |
| checking permissions           | 0.000006 |
| checking permissions           | 0.000006 |
| Opening tables                 | 0.002531 |
| init                           | 0.000011 |
| System lock                    | 0.000010 |
| optimizing                     | 0.000023 |
| statistics                     | 0.000114 |
| preparing                      | 0.000038 |
| Creating tmp table             | 0.000050 |
| executing                      | 0.000041 |
| checking permissions           | 0.000115 |
| end                            | 0.000007 |
| query end                      | 0.000006 |
| waiting for handler commit     | 0.000012 |
| closing tables                 | 0.000015 |
| freeing items                  | 0.000127 |
| cleaning up                    | 0.000073 |
+--------------------------------+----------+
20 rows in set, 1 warning (0.00 sec)

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论
SHOW PROFILESMySQL提供的用于分析当前会话中SQL语句执行的资源消耗情况的工具。以下是使用SHOW PROFILES的步骤: 1. 确认是否开启SHOW PROFILES功能。可以通过执行以下语句查看当前是否开启了SHOW PROFILES功能: ``` show variables like 'profiling'; ``` 如果结果为'ON',则表示SHOW PROFILES功能已经开启;如果结果为'OFF',则表示SHOW PROFILES功能未开启。 2. 执行需要分析的SQL语句。在执行SQL语句之后,可以使用以下语句获取到最近执行的SQL语句的Query_ID: ``` show profiles; ``` 3. 使用获取到的Query_ID进行SQL语句的分析。可以使用以下语句查看指定Query_ID的SQL语句执行的详细耗时、CPU和内存消耗: ``` show profile cpu,block io for query Query_ID; ``` 在这里,Query_ID是通过执行show profiles语句获取到的查询到的具体Query_ID。 请注意,SHOW PROFILES功能默认是关闭的,并且每次使用前都需要开启。SHOW PROFILES仅在当前会话中有效,不会影响其他会话。此外,SHOW PROFILES会保存最近执行的15条SQL语句的执行结果。<span class="em">1</span><span class="em">2</span><span class="em">3</span> #### 引用[.reference_title] - *1* *2* [mysql优化之show profile的使用及分析](https://blog.csdn.net/weixin_44540711/article/details/125893388)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v93^chatsearchT3_2"}}] [.reference_item style="max-width: 50%"] - *3* [MySQL调优利器【show profiles】](https://download.csdn.net/download/weixin_38565818/13687765)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v93^chatsearchT3_2"}}] [.reference_item style="max-width: 50%"] [ .reference_list ]
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

弦之森

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值