成都创新互联网站制作重庆分公司

Mysqlprofile怎么用

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

我们注重客户提出的每个要求,我们充分考虑每一个细节,我们积极的做好成都网站制作、网站设计服务,我们努力开拓更好的视野,通过不懈的努力,创新互联建站赢得了业内的良好声誉,这一切,也不断的激励着我们更好的服务客户。 主要业务:网站建设,网站制作,网站设计,小程序设计,网站开发,技术开发实力,DIV+CSS,PHP及ASP,ASP.Net,SQL数据库的技术开发工程师。

如何通过profile来发现语句的开销

构造场景:
开启一个回话,执行语句
lock table film_text read;

开启另外一个回话,执行下面语句:
root@sakila 07:51:14>show variables like '%profil%';
+------------------------+-------+
| Variable_name          | Value |
+------------------------+-------+
| have_profiling         | YES   |
| profiling              | OFF   |
| profiling_history_size | 15    |
+------------------------+-------+
3 rows in set (0.01 sec)

root@sakila 07:52:38>set profiling=1;
Query OK, 0 rows affected, 1 warning (0.00 sec)

root@sakila 07:52:45>update film_text set title='test' where film_id=1003;
Query OK, 0 rows affected (11.02 sec)
Rows matched: 1  Changed: 0  Warnings: 0


root@sakila 07:53:18>show profiles;
+----------+-------------+------------------------------------------------------+
| Query_ID | Duration    | Query                                                |
+----------+-------------+------------------------------------------------------+
|        1 | 11.02395150 | update film_text set title='test' where film_id=1003 |
+----------+-------------+------------------------------------------------------+
1 row in set, 1 warning (0.01 sec)


root@sakila 07:53:26>show profile for query 1;
+------------------------------+-----------+
| Status                       | Duration  |
+------------------------------+-----------+
| starting                     |  0.000793 |
| checking permissions         |  0.000032 |
| Opening tables               |  0.000087 |
| init                         |  0.000026 |
| System lock                  |  0.000025 |
| Waiting for table level lock | 11.018648 |
| System lock                  |  0.000770 |
| updating                     |  0.002947 |
| end                          |  0.000077 |
| query end                    |  0.000069 |
| closing tables               |  0.000062 |
| freeing items                |  0.000253 |
| cleaning up                  |  0.000163 |
+------------------------------+-----------+
13 rows in set, 1 warning (0.00 sec)


可以看到开销是在这个waiting table lock.

貌似 show profiles 只能显示本回话执行的sql语句的情况,即使设置了global profiling=1

所以如果要调优一组sql, 那么把这一组sql放到一个回话中执行,然后执行show profiles 查看每条语句的执行时间,并且进一步分析开销在什么地方。

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


文章标题:Mysqlprofile怎么用
网页地址:http://cxhlcq.com/article/pdhpgj.html

其他资讯

在线咨询

微信咨询

电话咨询

028-86922220(工作日)

18980820575(7×24)

提交需求

返回顶部