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

MySQL查找SQL耗时瓶颈 SHOW profiles

时间:2017-06-27 20:03:22      阅读:177      评论:0      收藏:0      [点我收藏+]

标签:bind   mat   view   tar   text   语法   key   net   target   

http://blog.csdn.net/k_scott/article/details/8804384

1、首先查看是否开启profiling功能
[sql] view plain copy
 
  1. SHOW VARIABLES LIKE ‘%pro%‘;  

或者

[sql] view plain copy
 
  1. SELECT @@profiling;  


2、开启profiling

[sql] view plain copy
 
  1. SET profiling=1;  

3、执行sql语句

例如:

[sql] view plain copy
 
  1. SELECT   
  2.   table_schema AS ‘Db Name‘,  
  3.   ROUND( SUM( data_length + index_length ) / 1024 / 1024, 3 ) AS ‘Db Size (MB)‘,  
  4.   ROUND( SUM( data_free ) / 1024 / 1024, 3 ) AS ‘Free Space (MB)‘  
  5. FROM information_schema.tables  
  6. GROUP BY table_schema ;  

4、查看结果

[sql] view plain copy
 
  1. SHOW profiles;  
[sql] view plain copy
 
  1. SHOW profile ALL FOR QUERY 94;  

94是查询ID号。

SHOW profiles语法:

[sql] view plain copy
 
  1. SHOW PROFILE [type [, type] … ]  
  2.     [FOR QUERY n]  
  3.     [LIMIT row_count [OFFSET offset]]  
  4.   
  5. type:  
  6.     ALL  
  7.   | BLOCK IO  
  8.   | CONTEXT SWITCHES  
  9.   | CPU  
  10.   | IPC  
  11.   | MEMORY  
  12.   | PAGE FAULTS  
  13.   | SOURCE  
  14.   | SWAPS  



 

 
 
 

MySQL查找SQL耗时瓶颈 SHOW profiles

标签:bind   mat   view   tar   text   语法   key   net   target   

原文地址:http://www.cnblogs.com/mydriverc/p/7086509.html

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