码迷,mamicode.com
首页 > 数据库 > 详细

explain和profiling分析查询SQL时间

时间:2018-04-21 19:48:07      阅读:243      评论:0      收藏:0      [点我收藏+]

标签:mysql   clip   where   sql   tool   hid   targe   overflow   时间   

mysql可以通过profiling命令查看到执行查询SQL消耗的时间。

默认情况下,mysql是关闭profiling的,命令:

  1. select @@profiling;  
+-------------------+

|    @@profiling    |

+-------------------+

|                     0   |

+-------------------+

说明:

0:表示profiling功能是关闭;

1:表示打开的。

可以通过命令打开/关闭profiling功能。

打开命令:

  1. set profiling=1;  
关闭命令:
  1. set profiling=0;  
如查询命令:

select * from employee limit 1,10;

可以使用profiling命令查看执行这条SQL消耗的时间:

  1. show profiles;  
查询结果:

+----------------+-----------------+-------------------------------------------------------------+

| Query_ID        | Duration         | Query                                                                     |

+----------------+-----------------+--------------------------------------------------------------+

|             1       | 0.00083225      | select * from employee limit 1,10                              |

+----------------+-----------------+--------------------------------------------------------------+

1 row in set ( 0.00 sec)

 

使用explain来分析是否命中索引

  1. mysql> explain select * from user where username = ‘a‘;  
  2. +----+-------------+-------+------+---------------+------------+---------+-------+------+-------------+  
  3. | id | select_type | table | type | possible_keys | key        | key_len | ref   | rows | Extra       |  
  4. +----+-------------+-------+------+---------------+------------+---------+-------+------+-------------+  
  5. |  1 | SIMPLE      | user  | ref  | user_index    | user_index | 62      | const |    1 | Using where |  
  6. +----+-------------+-------+------+---------------+------------+---------+-------+------+-------------+  
  7. 1 row in set (0.00 sec)  

可以看出已经命中索引user_index
 
 
 
 
 
 

explain和profiling分析查询SQL时间

标签:mysql   clip   where   sql   tool   hid   targe   overflow   时间   

原文地址:https://www.cnblogs.com/musings/p/8902439.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!