使用MySQL Profiling
##=====================================#### 查看PROFILING是否开启SELECT @@profiling## 开始会话级别PROFILINGSET profiling=1## 执行要检查的SQL## 查看捕获的所有SQLSHOW 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 TraceSET OPTIMIZER_TRACE="enabled=on",END_MARKERS_IN_JSON=on;## 设置MySQL Trace最大使用内存SET OPTIMIZER_TRACE_MAX_MEM_SIZE=100*1024*1024*1024;## 执行需要跟踪的SQL## 查看MySQL Trace捕获信息SELECT * FROM INFORMATION_SCHEMA.OPTIMIZER_TRACE \G## 关闭MySQL TraceSET optimizer_trace="enabled=off";