本文摘自PHP中文网,作者coldplay.xixi,侵删。
mysql教程介绍慢查询分析调优工具

推荐(免费):mysql教程(视频)
继上一篇mysqldumpslow工具的讲解,今天来聊聊show profile。也是MySQL服务自带的分析调优工具,不过这款更高级,比较接近底层硬件参数的调优。

查看show profile设置
1 | show variables like 'profiling%';
|

开启

查看最近15次的运行结果
1 2 3 | show profiles;
备注:
show warnings;
|

诊断运行的SQL
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 | 命令:show profile cpu,block io for query query_id;
例子:
show profile cpu,block io for query 3;
通过Status一列,可以看到整条SQL的运行过程
1. starting
2. checking permissions
3. Opening tables
4. init
5. System lock
6. optimizing
7. statistics
8. prepareing
9. executing
10. end
11. query end
......
12. closing tables
13. freeing items
14. cleaning up
|

1 2 3 4 5 6 7 8 9 10 | Type:
ALL
BLOCK IO
CONTEXT SWITCHES
CPU
IPC
MEMORY
PAGE FAULTS
SOURCE
SWAPS
|
1 2 3 4 5 | 如出现以下一种或者几种情况,说明SQL执行性能极其低下,亟需优化
* converting HEAP to MyISAM
* Creating tmp table
* Copying to tmp table on disk
* locked
|
通过查询数据表来诊断SQL(第二种查询方式)
1 | select * from information_schema.profiling;
|

全局查询日志(第二种SQL诊断方式)
1 | 此方式诊断较简单(参数少,适合定位有问题的SQL),记录到数据库(建议只在测试库环境进行)
|
设置
1 2 3 | 方式1:命令行
1. set global general_log = 1;
2. set global log_output = 'TABLE';
|
1 2 3 4 5 6 | 方式2:配置文件
* vim my.cnf
general_log =1
general_log_file = /path/logfile
log_output = FILE
* 重启MySQL服务
|
诊断SQL
1 | select * from mysql.general_log;
|

以上就是mysql的慢查询分析调优工具 show profile的详细内容,更多文章请关注木庄网络博客!
相关阅读 >>
mysql中普通、慢查询日志的区别
mysql多字段主键
mysql开放远程连接权限的两种方法
mysql日期和时间函数有哪些?
mysql中explain作用详解
mysql的安装与配置经验分享
如何使用mysql sandbox快速部署mysql
mysql的免安装版怎么用?
mysql如何登陆%_mysql?
理解mysql变量和条件
更多相关阅读请进入《mysql》频道 >>
机械工业出版社
本书主要讲述了数据模型、基于对象的数据库和XML、数据存储和查询、事务管理、体系结构等方面的内容。
转载请注明出处:木庄网络博客 » mysql的慢查询分析调优工具 show profile