MySQL优化之SQL耗时瓶颈 SHOW profiles

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.  
    6. type:  
    7.     ALL  
    8.   | BLOCK IO  
    9.   | CONTEXT SWITCHES  
    10.   | CPU  
    11.   | IPC  
    12.   | MEMORY  
    13.   | PAGE FAULTS  
    14.   | SOURCE  
    15.   | SWAPS  

 

原文地址:https://www.cnblogs.com/lpfuture/p/5748107.html