MySQL查找SQL耗时瓶颈 SHOW profiles
时间:2021-07-01 10:21:17
帮助过:23人阅读
- SHOW VARIABLES LIKE ‘%pro%‘;
或者
[sql] view plain
copy
- SELECT @@profiling;
2、开启profiling
[sql] view plain
copy
- SET profiling=1;
3、执行sql语句
例如:
[sql] view plain
copy
- 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、查看结果
[sql] view plain
copy
- SHOW profiles;
[sql] view plain
copy
- SHOW profile ALL FOR QUERY 94;
94是查询ID号。
SHOW profiles语法:
[sql] view plain
copy
- 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查找SQL耗时瓶颈 SHOW profiles
标签:bind mat view tar text 语法 key net target