mysql show profile

1、默认处于关闭状态,并保存最近15次的运行结果

2、查看当前版本是否支持

mysql show profile

3、开启

set profiling=on;

4、查看

mysql show profile

5、诊断SQL,show profile cpu,block io for query +query_id

mysql show profile

查询的类型可以为:

ALL-------显示所有信息

block id------显示块IO信息

context switches-------显示上下文切换信息

cpu----------显示CPU信息

ipc------显示发送和接收信息

memory-----显示内存信息

page faults------显示页面错误信息

source------显示和source_function,source_file,source_line相关的开销

swaps----显示交换次数相关开销

6、status中存在以下步骤一般需要优化

-----converting HEAP to MyISAM 查询结果太大,内存不够用了往磁盘上搬

-----creating tmp table 创建临时表

-----copying to tmp table on disk 把内存中临时表复制到磁盘

-----locked


--------------------------------------------------------------------------------

另外全局查询日志(会记录所有操作SQL,生产环境禁止使用)

1、配置启用

命令:

set global general_log=1;

set global log_output='TABLE';(记录存在表mysql库中的general_log表中,select查询即可看到)

文件配置:

my.cnf中

#开启

general_log=1

#文件路径

general_log_file=.......

#输出格式

log_output=FILE