MySQL性能分析show profiles

show profile 和 show profiles 语句可以展示当前会话(退出session后,profiling重置为0) 中执行语句的资源使用情况。

Profiling 功能由MySQL会话变量 : profiling控制,默认是OFF.关闭状态。select @@profiling; 或者show variables like '%profi%';

mysql> select @@profiling;
+-------------+
| @@profiling |
+-------------+
| |
+-------------+

Profiling是针对进程(process)而非线程(threads),因此运行在服务器上的其他服务进程可能会影响分析结果。Profiling 信息收集依赖于调用 系统方法 getrusage().因此Windows系统不适用。

开启Profiling功能:

mysql> set profiling = 1;
Query OK, 0 rows affected, 1 warning (0.00 sec)

退出会话后,Profiling功能自动关闭。

语句使用:

show profiles :列表,显示最近发送到服务器上执行的语句的资源使用情况.显示的记录数由变量:profiling_history_size 控制,默认15条。

mysql> show profiles;
+----------+------------+-------------------------------+
| Query_ID | Duration | Query |
+----------+------------+-------------------------------+
| 1 | 0.00371475 | show variables like '%profi%' |
| 2 | 0.00005700 | show prifiles |
| 3 | 0.00011775 | SELECT DATABASE() |
| 4 | 0.00034875 | select * from student |
+----------+------------+-------------------------------+

show profile: 展示最近一条语句执行的详细资源占用信息,默认显示 Status和Duration两列

mysql> show profile;
+----------------------+----------+
| Status | Duration |
+----------------------+----------+
| starting | 0.000054 |
| checking permissions | 0.000007 |
| Opening tables | 0.000116 |
| init | 0.000019 |
| System lock | 0.000009 |
| optimizing | 0.000004 |
| statistics | 0.000011 |
| preparing | 0.000010 |
| executing | 0.000002 |
| Sending data | 0.000061 |
| end | 0.000005 |
| query end | 0.000006 |
| closing tables | 0.000006 |
| freeing items | 0.000031 |
| cleaning up | 0.000010 |
+----------------------+----------+

show profile 还可根据 show profiles 列表中的 Query_ID ,选择显示某条记录的性能分析信息。

Syntax:
SHOW PROFILE [type [, type] ... ]
[FOR QUERY n]
[LIMIT row_count [OFFSET offset]] type: {
ALL
| BLOCK IO
| CONTEXT SWITCHES
| CPU
| IPC
| MEMORY
| PAGE FAULTS
| SOURCE
| SWAPS
}

实例:

Examples:
mysql> SELECT @@profiling;
+-------------+
| @@profiling |
+-------------+
| 0 |
+-------------+
1 row in set (0.00 sec) mysql> SET profiling = 1;
Query OK, 0 rows affected (0.00 sec) mysql> DROP TABLE IF EXISTS t1;
Query OK, 0 rows affected, 1 warning (0.00 sec) mysql> CREATE TABLE T1 (id INT);
Query OK, 0 rows affected (0.01 sec) mysql> SHOW PROFILES;
+----------+----------+--------------------------+
| Query_ID | Duration | Query |
+----------+----------+--------------------------+
| 0 | 0.000088 | SET PROFILING = 1 |
| 1 | 0.000136 | DROP TABLE IF EXISTS t1 |
| 2 | 0.011947 | CREATE TABLE t1 (id INT) |
+----------+----------+--------------------------+
3 rows in set (0.00 sec) mysql> SHOW PROFILE;
+----------------------+----------+
| Status | Duration |
+----------------------+----------+
| checking permissions | 0.000040 |
| creating table | 0.000056 |
| After create | 0.011363 |
| query end | 0.000375 |
| freeing items | 0.000089 |
| logging slow query | 0.000019 |
| cleaning up | 0.000005 |
+----------------------+----------+
7 rows in set (0.00 sec) mysql> SHOW PROFILE FOR QUERY 1;
+--------------------+----------+
| Status | Duration |
+--------------------+----------+
| query end | 0.000107 |
| freeing items | 0.000008 |
| logging slow query | 0.000015 |
| cleaning up | 0.000006 |
+--------------------+----------+
4 rows in set (0.00 sec) mysql> SHOW PROFILE CPU FOR QUERY 2;
+----------------------+----------+----------+------------+
| Status | Duration | CPU_user | CPU_system |
+----------------------+----------+----------+------------+
| checking permissions | 0.000040 | 0.000038 | 0.000002 |
| creating table | 0.000056 | 0.000028 | 0.000028 |
| After create | 0.011363 | 0.000217 | 0.001571 |
| query end | 0.000375 | 0.000013 | 0.000028 |
| freeing items | 0.000089 | 0.000010 | 0.000014 |
| logging slow query | 0.000019 | 0.000009 | 0.000010 |
| cleaning up | 0.000005 | 0.000003 | 0.000002 |
+----------------------+----------+----------+------------+
7 rows in set (0.00 sec)

mysql性能分析show profile/show profiles的更多相关文章

  1. MySQL性能分析及explain的使用

    MySQL性能分析及explain用法的知识 1.使用explain语句去查看分析结果 如explain select * from test1 where id=1;会出现:id  selectty ...

  2. MySQL性能分析及explain的使用说明

    1.使用explain语句去查看分析结果 如explain select * from test1 where id=1;会出现:id selecttype table type possible_k ...

  3. MySQL性能分析和优化-part 1

    MySQL性能优化 平时我们在使用MySQL的时候,怎么评估系统的运行状态,怎么快速定位系统瓶颈,又如何快速解决问题呢? 本文总结了多年来MySQL优化的经验,系统介绍MySQL优化的方法. OS性能 ...

  4. Python性能分析工具Profile

    Python性能分析工具Profile 代码优化的前提是需要了解性能瓶颈在什么地方,程序运行的主要时间是消耗在哪里,对于比较复杂的代码可以借助一些工具来定位,python 内置了丰富的性能分析工具,如 ...

  5. MySQL性能分析, mysql explain执行计划详解

    MySQL性能分析 MySQL性能分析及explain用法的知识是本文我们主要要介绍的内容,接下来就让我们通过一些实际的例子来介绍这一过程,希望能够对您有所帮助. 1.使用explain语句去查看分析 ...

  6. mysql性能分析工具

    一.EXPALIN 在SQL语句之前加上EXPLAIN关键字就可以获取这条SQL语句执行的计划 那么返回的这些字段是什么呢? 我们先关心一下比较重要的几个字段: 1. select_type 查询类型 ...

  7. mysql性能分析-------profiling和explain

    1. profiling之性能分析 MySQL5.0.37版本以上支持了Profiling – 官方手册.此工具可用来查询 SQL 会执行多少时间,System lock和Table lock 花多少 ...

  8. MySQL性能分析(转)

    第一步:检查系统的状态 通过操作系统的一些工具检查系统的状态,比如CPU.内存.交换.磁盘的利用率.IO.网络,根据经验或与系统正常时的状态相比对,有时系统表面上看起来看空闲,这也可能不是一个正常的状 ...

  9. MySQL性能分析、及调优工具使用详解

    本文汇总了MySQL DBA日常工作中用到的些工具,方便初学者,也便于自己查阅. 先介绍下基础设施(CPU.IO.网络等)检查的工具: vmstat.sar(sysstat工具包).mpstat.op ...

随机推荐

  1. jquery.datatables设置列隐藏的方法

    项目需要根据权限设置表格(使用Juqery.datatables,版本:1.10.16)某列显示或隐藏,百度后有两种实现方法: 1.在columns中设置: columns:[{data:" ...

  2. 第三十二课 linux内核链表剖析

    __builtin_prefetch是gcc扩展的,用来提高访问效率,需要硬件的支持. 在标准C语言中是不允许static inline联合使用的. 删除依赖的头文件,将相应的结构拷贝到LinuxLi ...

  3. 论container的前世今生

    why Normally, thin-client multitiered applications are hard to write because they involve many lines ...

  4. Web应用 布局

    asp.net core系列 44 Web应用 布局 一.概述 MVC的视图与Razor页面经常共享视觉和程序元素,通过使用布局来完成,布局还可减少重复代码.本章演示了以下内容的操作方法:(1)使用通 ...

  5. 开发工具-Eclipse

    1.Eclipse的视窗和视图概述 - A:视窗 每一个基本的窗体被称为视窗  * PackageExplorer 显示项目结构,包,类,及资源   * Outline 显示类的结构,方便查找,识别, ...

  6. C++学习(十八)(C语言部分)之 指针2

    指针1.指针的概述 指针是什么? 指针是一个地址 是一个常量 int 整型 int a a是变量 指针用来做什么? 方便使用数组或者字符串 像汇编语言一样处理内存地址2.指针变量 什么是指针变量? 是 ...

  7. 【湖南师范大学2018年大学生程序设计竞赛新生赛 L】【HDOJ2476】【区间DP】

    https://www.nowcoder.com/acm/contest/127/L L 小小粉刷匠 题目描述 "lalala,我是一个快乐的粉刷匠",小名一边快活地唱着歌,一边开 ...

  8. oracle ZHS16GBK的数据库导入到字符集为AL32UTF8的数据库(转载+自己经验总结)

    字符集子集向其超集转换是可行的,如此例 ZHS16GBK转换为AL32UTF8. 导出使用的字符集将会记录在导出文件中,当文件导入时,将会检查导出时使用的字符集设置,如果这个字符集不同于导入客户端的N ...

  9. XML之命名空间的作用(xmlns)

    http://www.w3school.com.cn/xml/xml_namespaces.asp http://blog.csdn.net/zhch152/article/details/81913 ...

  10. crash - JNI WARNING: input is not valid modified utf-8: illegal continuation byte

    the key point is "Modified UTF-8" is not like "Regular UTF-8", a legal Rgular UT ...