首页 > 代码库 > MySQL查找SQL耗时瓶颈 SHOW profiles
MySQL查找SQL耗时瓶颈 SHOW profiles
http://blog.csdn.net/k_scott/article/details/8804384
1、首先查看是否开启profiling功能
[sql] view plain copy
- 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
声明:以上内容来自用户投稿及互联网公开渠道收集整理发布,本网站不拥有所有权,未作人工编辑处理,也不承担相关法律责任,若内容有误或涉及侵权可进行投诉: 投诉/举报 工作人员会在5个工作日内联系你,一经查实,本站将立刻删除涉嫌侵权内容。