mysql5.7版本官方文档地址
https://dev.mysql.com/doc/refman/5.7/en/show-profile.html
主要语法
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
}
- 启用
set profiling=1;
- 查看查询消耗的时间
SELECT * FROM `user`;
SHOW PROFILES;
4. 查看单次查询消耗的具体时间
# 1 为 Query_ID 对应的值
show profile for query 1;
5. 查询各种资源的消耗
show profile all for query 1 \G
SHOW PROFILE语句已经弃用,并将在以后版本中移除,建议使用 Performance Schema
The SHOW PROFILE and SHOW PROFILES statements are deprecated and will be removed in a future MySQL release. Use the Performance Schema instead;