mysql profile可以帮助我们分析一条命令的执行过程和每个过程耗时情况。
主要用法有三句:
1.启用set profiling=1;
2.显示概要show profiles;
3显示一条语句详情show profile for query 1; 1是第二步中的概要id
mysql> set profiling=1;
mysql> show profiles;
+----------+------------+-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
| Query_ID | Duration | Query |
+----------+------------+-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
| 1 | 0.00010950 | SELECT `uid`, `did`, `im1`, `model`, IF(`vern`='2.7.012-SNAPSHOT' && `verc`=427000, 0, 1) as `update` FROM `device` WHERE `did` = 'dcc8dd793075c6e9' OR (`im1` = 578753589687764 AND `model` = 'test_model' ) |
| 2 | 0.00010850 | SELECT `uid`, `did`, `im1`, `model`, `vern`, `verc` FROM `device` WHERE `did` = 'dcc8dd793075c6e9' OR (`im1` = 578753589687764 AND `model` = 'test_model' ) |
+----------+------------+-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
2 rows in set (0.00 sec)
mysql> show profile for query 1;
+--------------------------------+----------+
| Status | Duration |
+--------------------------------+----------+
| starting | 0.000067 |
| Waiting for query cache lock | 0.000007 |
| checking query cache for query | 0.000008 |
| checking privileges on cached | 0.000003 |
| checking permissions | 0.000008 |
| sending cached result to clien | 0.000013 |
| logging slow query | 0.000003 |
| cleaning up | 0.000003 |
+--------------------------------+----------+
8 rows in set (0.00 sec)