mysql> show profiles;
+----------+--------------+-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
| Query_ID | Duration | Query |
+----------+--------------+-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
| 7 | 0.00022275 | SELECT * FROM setup_actors |
| 8 | 0.00016050 | SELECT DATABASE() |
| 9 | 0.00032350 | show databases |
| 10 | 0.00024050 | show tables |
| 11 | 0.00019250 | SELECT * FROM setup_actors |
| 12 | 0.00183950 | show variables like "profiling_hist%" |
| 13 | 0.00192500 | show variables like '%profil%' |
| 14 | 0.00011550 | show warnings |
| 15 | 0.00044725 | help 'show profile' |
| 16 | 0.00013875 | set profiling=1 |
| 17 | 0.00011550 | show warnings |
| 18 | 0.00025075 | select * from customers where `type` = 1 AND `status` < 7 AND `isarea` = 6 AND `into_time`>='2016-12-01'AND `into_time`<='2017-01-02 23:59:59' order by score desc limit 40,20 |
| 19 | 333.19133875 | select * from oms3.customers where `type` = 1 AND `status` < 7 AND `isarea` = 6 AND `into_time`>='2016-12-01'AND `into_time`<='2017-01-02 23:59:59' order by score desc limit 40,20 |
| 20 | 0.00011250 | show profilings |
| 21 | 0.00010975 | show profilings |
+----------+--------------+-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
15 rows in set, 1 warning (0.00 sec)
mysql> set @query_id=19; ---上面显示是query_id为19
Query OK, 0 rows affected (0.00 sec)
mysql> select STATE,sum(duration) as Total_R, ---用这条sql查询具体是哪里出问题,这条sql引用于《High Performance MySQL,Third Edition》
-> ROUND(
-> 100*SUM(DURATION)/
-> (SELECT SUM(DURATION) FROM INFORMATiON_SCHEMA.PROFILING WHERE QUERY_ID=@query_id),2) as Pct_R,
-> count(*) as calls,
-> sum(duration)/count(*) as "R/Call"
-> from information_schema.profiling
-> where query_id=@query_id
-> group by state
-> order by Total_R desc;
+----------------------+------------+-------+-------+----------------+
| STATE | Total_R | Pct_R | calls | R/Call |
+----------------------+------------+-------+-------+----------------+
| Sending data | 332.162424 | 99.69 | 1 | 332.1624240000 | ---这个state基本占用了全部的资源,那么对这条sql的优化就着重于减少io上。
| statistics | 1.027729 | 0.31 | 1 | 1.0277290000 |
| Opening tables | 0.000519 | 0.00 | 1 | 0.0005190000 |
| freeing items | 0.000157 | 0.00 | 1 | 0.0001570000 |
| starting | 0.000147 | 0.00 | 1 | 0.0001470000 |
| init | 0.000123 | 0.00 | 1 | 0.0001230000 |
| logging slow query | 0.000096 | 0.00 | 1 | 0.0000960000 |
| preparing | 0.000035 | 0.00 | 1 | 0.0000350000 |
| cleaning up | 0.000019 | 0.00 | 1 | 0.0000190000 |
| optimizing | 0.000016 | 0.00 | 1 | 0.0000160000 |
| end | 0.000014 | 0.00 | 1 | 0.0000140000 |
| System lock | 0.000014 | 0.00 | 1 | 0.0000140000 |
| closing tables | 0.000013 | 0.00 | 1 | 0.0000130000 |
| query end | 0.000013 | 0.00 | 1 | 0.0000130000 |
| Sorting result | 0.000010 | 0.00 | 1 | 0.0000100000 |
| checking permissions | 0.000009 | 0.00 | 1 | 0.0000090000 |
| executing | 0.000003 | 0.00 | 1 | 0.0000030000 |
+----------------------+------------+-------+-------+----------------+
17 rows in set, 18 warnings (0.00 sec)
以上是“MySQL性能分析工具之PROFILE怎么用”这篇文章的所有内容,感谢各位的阅读!相信大家都有了一定的了解,希望分享的内容对大家有所帮助,如果还想学习更多知识,欢迎关注天达云行业资讯频道!