MySQL查找SQL耗时瓶颈 SHOW profiles

来源:互联网 发布:oracle数据库跟踪工具 编辑:程序博客网 时间:2024/05/22 09:41
1、首先查看是否开启profiling功能
  1. SHOW VARIABLES LIKE '%pro%';  

或者

  1. SELECT @@profiling;  


2、开启profiling

  1. SET profiling=1;  

3、执行sql语句

例如:

  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、查看结果

  1. SHOW profiles;  
  1. SHOW profile ALL FOR QUERY 94;  

94是查询ID号。

SHOW profiles语法:

  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  


0 0
原创粉丝点击