mysql 慢查询 show_Mysql 慢查询之showprofile

show profiles:返回服务器上最近执行的语句 资源的使用情况。

一、使用准备

Show profiles是5.0.37之后添加的,要想使用此功能,要确保版本在5.0.37之后。

mysql> select version();

+-----------+

| version() |

+-----------+

| 5.5.36 |

+-----------+

profile 功能默认是关闭的 通过以下命令查看 ,开启

mysql> select @@profiling;

+-------------+

| @@profiling |

+-------------+

| 0 |

+-------------+

mysql> show variables like '%profiling%';

+------------------------+-------+

| Variable_name | Value |

+------------------------+-------+

| have_profiling | YES |

| profiling | OFF |

| profiling_history_size | 15 |

+------------------------+-------+

mysql> set global profiling = 1;

mysql> set global profiling_history_size = 10;

其中 profiling_history_size为保存多少条最近记录。

重开会话后显示生效。

二、具体语法

查看记录中的语句

mysql> show profiles;

+----------+------------+---------------------------------------------+

| Query_ID | Duration | Query |

+----------+------------+---------------------------------------------+

| 1 | 0.00015600 | select @@version_comment limit 1 |

| 2 | 0.00056675 | show variables like '%profiling%' |

| 3 | 0.00007050 | select * from b limit 10000 |

| 4 | 0.00014075 | SELECT DATABASE() |

| 5 | 0.00592575 | select * from b limit 10000 |

| 6 | 0.06692075 | select * from b group by id%10 limit 10000 |

| 7 | 0.06478225 | select * from b group by id%10 limit 100000 |

+----------+------------+---------------------------------------------+

查看表中 具体记录的详细执行信息

show profile [参数[,参数...]] for query [上面的Query_ID]

mysql> show profile cpu,block io for query 7;

+----------------------+----------+----------+------------+--------------+---------------+

| Status | Duration | CPU_user | CPU_system | Block_ops_in | Block_ops_out |

+----------------------+----------+----------+------------+--------------+---------------+

| starting | 0.000060 | 0.000000 | 0.000000 | NULL | NULL |

| checking permissions | 0.000004 | 0.000000 | 0.000000 | NULL | NULL |

| Opening tables | 0.000026 | 0.000000 | 0.000000 | NULL | NULL |

| System lock | 0.000006 | 0.000000 | 0.000000 | NULL | NULL |

| init | 0.000013 | 0.000000 | 0.000000 | NULL | NULL |

| optimizing | 0.000003 | 0.000000 | 0.000000 | NULL | NULL |

| statistics | 0.000014 | 0.000000 | 0.000000 | NULL | NULL |

| preparing | 0.000005 | 0.000000 | 0.000000 | NULL | NULL |

| Creating tmp table | 0.000288 | 0.000000 | 0.000000 | NULL | NULL |

| executing | 0.000003 | 0.000000 | 0.000000 | NULL | NULL |

| Copying to tmp table | 0.064244 | 0.062500 | 0.000000 | NULL | NULL |

| Sorting result | 0.000021 | 0.000000 | 0.000000 | NULL | NULL |

| Sending data | 0.000011 | 0.000000 | 0.000000 | NULL | NULL |

| end | 0.000002 | 0.000000 | 0.000000 | NULL | NULL |

| removing tmp table | 0.000006 | 0.000000 | 0.000000 | NULL | NULL |

| end | 0.000002 | 0.000000 | 0.000000 | NULL | NULL |

| query end | 0.000002 | 0.000000 | 0.000000 | NULL | NULL |

| closing tables | 0.000004 | 0.000000 | 0.000000 | NULL | NULL |

| freeing items | 0.000046 | 0.000000 | 0.000000 | NULL | NULL |

| logging slow query | 0.000023 | 0.000000 | 0.000000 | NULL | NULL |

| cleaning up | 0.000001 | 0.000000 | 0.000000 | NULL | NULL |

+----------------------+----------+----------+------------+--------------+---------------+

可选参数:

ALL                                     显示所有信息

BLOCK IO                          块设备IO输入输出次数

CONTEXT SWITCHES     上下文切换的相关开销

CPU                                   用户和系统的CPU使用情况

IPC                                     发送和接收消息的相关消耗

MEMEORY                         内存相关消耗

PAGE FAULTS                   主要和次要页面故障的开销

SOURCE                           source_function,source_file 等相关开销

SWAPS                             交换次数开销

表中遇到Status 需要注意执行时间

converting HEAP to MySIAM  数据过大MyISAM内存装不下,向磁盘上搬运

Creating tmp table                   临时表创建

Copying to tmp table on disk  复制临时表到磁盘

locked                                      锁。阻塞

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值