MySQL查找SQL耗時瓶頸SHOW profiles 1、首先查看是否開啟profiling功能 SHOW VARIABLES LIKE '%pro%'; 或者 SELECT @@profiling; 2、開啟profiling SET profiling=1; 3、執行sql語句 例如: SELECT table_schema AS 'Db Name', ROUND( SUM( data_length + index_length ) / 1024 / 1024, 3 ) AS 'Db Size (MB)', ROUND( SUM( data_free ) / 1024 / 1024, 3 ) AS 'Free Space (MB)' FROM information_schema.tables GROUP BY table_schema ; 4、查看結果 SHOW profiles; SHOW profile ALL FOR QUERY 94; 94是查詢ID號。 SHOW profiles語法: SHOW PROFILE [type [, type] … ] [FOR QUERY n] [LIMIT row_count [OFFSET offset]] type: ALL | BLOCK IO | CONTEXT SWITCHES | CPU | IPC | MEMORY | PAGE FAULTS | SOURCE | SWAPS