慢查询分析show profile 调优工具

    show profile。也是 MySQL 服务自带的分析调优工具,不过这款更高级,比较接近底层硬件参数的调优。

慢查询分析show profile 调优工具

慢查询分析调优工具~show profile
查看 show profile 设置

show variables like 'profiling%';//默认关闭,保存近15次的运行结果

慢查询分析show profile 调优工具

慢查询分析调优工具~show profile
开启

set profiling = on;

慢查询分析调优工具~show profile

慢查询分析show profile 调优工具
查看最近 15 次的运行结果

show profiles;
备注:
show warnings;//可以显示警告和报错的信息

慢查询分析show profile 调优工具

慢查询分析调优工具~show profile
诊断运行的 SQL

慢查询分析show profile 调优工具

慢查询分析show profile 调优工具

慢查询分析show profile 调优工具

慢查询分析show profile 调优工具

 

通过查询数据表来诊断 SQL(第二种查询方式)

select * from information_schema.profiling;

慢查询分析show profile 调优工具

 
全局查询日志(第二种 SQL 诊断方式)

此方式诊断较简单(参数少,适合定位有问题的SQL),记录到数据库(建议只在测试库环境进行)

设置

方式1:命令行
1. set global general_log = 1;
2. set global log_output = 'TABLE';

方式2:配置文件
* vim my.cnf
general_log =1
general_log_file = /path/logfile
log_output = FILE
* 重启MySQL服务

诊断 SQL

select * from mysql.general_log;

慢查询分析调优工具~show profile
mysql show profile