MySQL中profiling有什么用

这篇文章将为大家详细讲解有关MySQL中profiling有什么用,小编觉得挺实用的,因此分享给大家做个参考,希望大家阅读完这篇文章后可以有所收获。

成都服务器托管,创新互联提供包括服务器租用、雅安移动机房、带宽租用、云主机、机柜租用、主机租用托管、CDN网站加速、国际域名空间等业务的一体化完整服务。电话咨询:18982081108

    MySQL5.0版本之后开放了profiling功能,通过此功能可以查询某个SQL的详细执行计划。
1、开启profiling
mysql> show variables like '%profil%';
+------------------------+-------+
| Variable_name          | Value |
+------------------------+-------+
| have_profiling           | YES   |
| profiling                     | ON    |
| profiling_history_size | 15    |
+------------------------+-------+
2、执行SQL,进行测试
mysql> select * from xcredit.tb_sync_job_bak;
3、查看profiles
mysql> show profiles;
+----------+------------+------------------------------------------------------------------------------+
| Query_ID | Duration   | Query                                                                        |
+----------+------------+------------------------------------------------------------------------------+
|        1 | 0.00009600 | set global profiling=1                                                       |
|        2 | 0.00218100 | show variables like '%profil%'                                               |
|        3 | 0.04091100 | select * from xcredit.tb_sync_job_bak where lid<1000 group by lid limit 5000 |
|        4 | 0.00019800 | select * from xcredit.tb_sync_job_bak where lid<1000 group by lid            |
|        5 | 0.16355550 | select * from xcredit.tb_sync_job_bak where lid<1000                         |
|        6 | 0.00230025 | show variables like '%profil%'                                               |
|        7 | 0.00014375 | select * from xcredit.tb_sync_job_bak group by lid%20 order by lid           |
|        8 | 0.00013600 | select * from xcredit.tb_sync_job_bak group by lid%20 order by 1             |
|        9 | 0.00013375 | select * from xcredit.tb_sync_job_bak group by lid%20                        |
|       10 | 0.26594500 | select * from xcredit.tb_sync_job_bak                                        |
+----------+------------+------------------------------------------------------------------------------+
4、查看执行计划
mysql> show profile for query 10;
+----------------------+----------+
| Status               | Duration |
+----------------------+----------+
| starting             | 0.000053 |
| checking permissions | 0.000005 |
| Opening tables       | 0.000014 |
| init                 | 0.000014 |
| System lock          | 0.000006 |
| optimizing           | 0.000003 |
| statistics           | 0.000010 |
| preparing            | 0.000009 |
| executing            | 0.000001 |
| Sending data         | 0.265498 |
| end                  | 0.000009 |
| query end            | 0.000010 |
| closing tables       | 0.000008 |
| freeing items        | 0.000258 |
| logging slow query   | 0.000036 |
| cleaning up          | 0.000011 |
+----------------------+----------+
此查询返回八万多行数据,返回数据量较大,因此出现sending data。

关于“MySQL中profiling有什么用”这篇文章就分享到这里了,希望以上内容可以对大家有一定的帮助,使各位可以学到更多知识,如果觉得文章不错,请把它分享出去让更多的人看到。

名称栏目:MySQL中profiling有什么用
本文链接:https://www.cdcxhl.com/article28/jodgcp.html

成都网站建设公司_创新互联,为您提供移动网站建设虚拟主机网站策划App开发企业建站

广告

声明:本网站发布的内容(图片、视频和文字)以用户投稿、用户转载内容为主,如果涉及侵权请尽快告知,我们将会在第一时间删除。文章观点不代表本网站立场,如需处理请联系客服。电话:028-86922220;邮箱:631063699@qq.com。内容未经允许不得转载,或转载时需注明来源: 创新互联

网站优化排名