本文摘自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导致登录phpmyadmin报错
mysql5.7单实例自启动服务配置过程
mysql 存储过程详解
mysql事务管理的介绍(附示例)
什么是脏读?
pk主键是什么意思?
更多相关阅读请进入《mysql》频道 >>
机械工业出版社
本书主要讲述了数据模型、基于对象的数据库和XML、数据存储和查询、事务管理、体系结构等方面的内容。
转载请注明出处:木庄网络博客 » mysql的慢查询分析调优工具 show profile