单条查询剖析
使用SHOW PROFILE
首先需要开启,默认是禁用的。
mysql> set profiling =1;
-- 创建一条查询语句
mysql> select * from table_name;
-- 使用show profiles 查看执行时间及查询sql;
-- 注意 这条sql 必须是profiling 开启后的查询才能出现。
mysql> show profiles;
-> //
+----------+------------+--------------------------+
| Query_ID | Duration | Query |
+----------+------------+--------------------------+
| 1 | 0.00241275 | select * from table_name |
+----------+------------+--------------------------+
1 row in set, 1 warning (0.00 sec)
-- 详细的执行时间
mysql> show profile for query 1;
-> //
+--------------------------------+----------+
| Status | Duration |
+--------------------------------+----------+
| starting | 0.000060 |
| Executing hook on transaction | 0.000004 |
| starting | 0.000007 |
| checking permissions | 0.000005 |
| Opening tables | 0.000041 |
| init | 0.000004 |
| System lock | 0.000009 |
| optimizing | 0.000003 |
| statistics | 0.000019 |
| preparing | 0.000015 |
| executing | 0.002076 |
| end | 0.000003 |