使用MySQL Profiling
##=====================================##
## 查看PROFILING是否开启
SELECT @@profiling ## 开始会话级别PROFILING
SET profiling=1 ## 执行要检查的SQL ## 查看捕获的所有SQL
SHOW PROFILES ## 看看特定SQL的执行信息
SHOW PROFILE CPU,BLOCK IO,SWAPS FOR QUERY 1; ##=====================================##
##SHOW PROFILE语法:
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
使用MySQL Trace
## 开启MySQL Trace
SET OPTIMIZER_TRACE="enabled=on",END_MARKERS_IN_JSON=on; ## 设置MySQL Trace最大使用内存
SET OPTIMIZER_TRACE_MAX_MEM_SIZE=***; ## 执行需要跟踪的SQL ## 查看MySQL Trace捕获信息
SELECT * FROM INFORMATION_SCHEMA.OPTIMIZER_TRACE \G ## 关闭MySQL Trace
SET optimizer_trace="enabled=off";