通过show profile分析sql语句
set profling=1;
select count(*) from xuehao;
show profiles;
show profile for query 1;
mysql> set profiling=1;
Query OK, 0 rows affected, 1 warning (0.00 sec)
mysql> select count(*) from xuehao;
+----------+
| count(*) |
+----------+
| 8 |
+----------+
1 row in set (0.00 sec)
mysql> show profiles;
+----------+------------+-----------------------------+
| Query_ID | Duration | Query |
+----------+------------+-----------------------------+
| 1 | 0.00034675 | select count(*) from xuehao |
+----------+------------+-----------------------------+
1 row in set, 1 warning (0.02 sec)
mysql> show profile for query 1;
+----------------------+----------+
| Status | Duration |
+----------------------+----------+
| starting | 0.000142 |
| checking permissions | 0.000015 |
| Opening tables | 0.000049 |
| init | 0.000036 |
| System lock | 0.000021 |
| optimizing | 0.000017 |
| executing | 0.000023 |
| end | 0.000005 |
| query end | 0.000003 |
| closing tables | 0.000012 |
| freeing items | 0.000011 |
| cleaning up | 0.000015 |
+----------------------+----------+
12 rows in set, 1 warning (0.14 sec)
mysql支持进一步选择all,cpu,block io,context,switch,page faults等明细类型来查看mysql在使用什么资源上消费了过高的时间。例如,选择查看cpu的耗费时间
mysql> show profile cpu for query 1;
+----------------------+----------+----------+------------+
| Status | Duration | CPU_user | CPU_system |
+----------------------+----------+----------+------------+
| starting | 0.000142 | 0.000000 | 0.000000 |
| checking permissions | 0.000015 | 0.000000 | 0.000000 |
| Opening tables | 0.000049 | 0.000000 | 0.000000 |
| init | 0.000036 | 0.000000 | 0.000000 |
| System lock | 0.000021 | 0.000000 | 0.000000 |
| optimizing | 0.000017 | 0.000000 | 0.000000 |
| executing | 0.000023 | 0.000000 | 0.000000 |
| end | 0.000005 | 0.000000 | 0.000000 |
| query end | 0.000003 | 0.000000 | 0.000000 |
| closing tables | 0.000012 | 0.000000 | 0.000000 |
| freeing items | 0.000011 | 0.000000 | 0.000000 |
| cleaning up | 0.000015 | 0.000000 | 0.000000 |
+----------------------+----------+----------+------------+
mysql> show profile source for query 1;
+----------------------+----------+-----------------------+------------------+-------------+
| Status | Duration | Source_function | Source_file | Source_line |
+----------------------+----------+-----------------------+------------------+-------------+
| starting | 0.000142 | NULL | NULL | NULL |
| checking permissions | 0.000015 | check_access | sql_parse.cc | 5256 |
| Opening tables | 0.000049 | open_tables | sql_base.cc | 4911 |
| init | 0.000036 | mysql_prepare_select | sql_select.cc | 1050 |
| System lock | 0.000021 | mysql_lock_tables | lock.cc | 304 |
| optimizing | 0.000017 | optimize | sql_optimizer.cc | 138 |
| executing | 0.000023 | exec | sql_executor.cc | 110 |
| end | 0.000005 | mysql_execute_select | sql_select.cc | 1105 |
| query end | 0.000003 | mysql_execute_command | sql_parse.cc | 4956 |
| closing tables | 0.000012 | mysql_execute_command | sql_parse.cc | 5004 |
| freeing items | 0.000011 | mysql_parse | sql_parse.cc | 6264 |
| cleaning up | 0.000015 | dispatch_command | sql_parse.cc | 1774 |
+----------------------+----------+-----------------------+------------------+-------------+
12 rows in set, 1 warning (0.00 sec)
通过show profile分析sql语句的更多相关文章
- 查看mysql正在执行的SQL语句,使用profile分析SQL执行状态
http://qq85609655.iteye.com/blog/2113960 1)我们先通过status命令查看Mysql运行状态 mysql> status; -------------- ...
- 如何使用SQLPLUS分析SQL语句(查询执行计划跟踪)
方法一:autotrace 1, connect sys/密码 as sysdba,在sys用户下运行$ORACLE_HOME/sqlplus/admin/plustrce.sql这段sql的实际内 ...
- mysql优化(三)–explain分析sql语句执行效率
mysql优化(三)–explain分析sql语句执行效率 mushu 发布于 11个月前 (06-04) 分类:Mysql 阅读(651) 评论(0) Explain命令在解决数据库性能上是第一推荐 ...
- 使用explain来分析SQL语句实现优化SQL语句
用法:explain sql 作用:用于分析sql语句 mysql> explain select * from quser_1 where loginemail = "quctest ...
- oracle v$sqlarea 分析SQL语句使用资源情况 确认是否绑定变量
-如何确定系统中是否存在绑定变量的情况:首先创建一个表,用于存放整理过得数据:create table t1 as select sql_text from v$sqlarea;----V$SQLAR ...
- Mysql explain分析sql语句执行效率
mysql优化–explain分析sql语句执行效率 Explain命令在解决数据库性能上是第一推荐使用命令,大部分的性能问题可以通过此命令来简单的解决,Explain可以用来查看SQL语句的执行效 ...
- 通过profile优化SQL语句
开启profile优化SQL语句:set profiling=1;执行SQL语句show profiles;show profile for query 2;//根据query_id 查看某个查询的详 ...
- mysql分析sql语句基础工具 -- explain
分析sql语句 explain explain (sql语句) G; 分析结果: id sql语句编号如果是连接查询,表之间是平等关系,编号相同:如果有子查询,编号递增. select——type 查 ...
- oracle用EXPLAIN PLAN 分析SQL语句
EXPLAIN PLAN 是一个很好的分析SQL语句的工具,它甚至可以在不执行SQL的情况下分析语句. 通过分析,我们就可以知道ORACLE是怎么样连接表,使用什么方式扫描表(索引扫描或全表扫描)以及 ...
随机推荐
- IO 的五种模型是什么
目录 前言 用户空间和内核空间 IO 五种模型 阻塞型 IO 非阻塞 IO IO 多路复用 信号驱动 IO 异步 IO 总结 阻塞和非阻塞 同步与异步 前言 我们经常看到阻塞/非阻塞,同步/异步这两组 ...
- cocosCreator微信小游戏排行榜思路
cocosCreator制作微信小游戏排行榜实现方案: 游戏认知:项目分为主域和子域,主域就是游戏主程部分,子域为单独处理微信排行榜公共域数据的. 游戏主域里创建一个节点,添加WXSubContext ...
- Jenkins的war包安装
安装Jenkins首先要安装jdk,在官网下载jdk安装并配置环境变量 1.Jenkins下载地址,下载war包 https://www.jenkins.io/download/ 2.打开命令行窗口, ...
- 设置定时任务用rman删除归档日志脚本
之前使用数据库数据迁移过程中出现产生大量归档日志的情况(由于迁移的目标库是DG,必须开启归档). 为避免出现归档空间爆掉的情况,设置定时任务删除系统当前时间30分钟前的归档日志,脚本如下: cat d ...
- 密码管理平台ratticdb的部署,在centos7上的部署
一,前言 一直想用ratticdb这个有web界面的密码管理工具,百度了一下居然没有找到中文的部署文档,访问官网也是notfound.找到了官方的部署指南:https://github.com/til ...
- 最全Python正则表达式来袭
前言 正则表达式是对字符串(包括普通字符(例如,a 到 z 之间的字母)和特殊字符(称为"元字符"))操作的一种逻辑公式,就是用事先定义好的一些特定字符.及这些特定字符的组合,组成 ...
- 前中后序递归遍历树的体会 with Python
前序:跟->左->右 中序:左->根->右 后序:左>右->根 采用递归遍历时,编译器/解释器负责将递归函数调用过程压入栈并保护现场,在不同位置处理根节点即可实现不 ...
- Centos8自动挂载U盘移动硬盘解决办法
Centos默认是不能识别NTFS文件系统的U盘.移动硬盘的.查阅了很多资料讲到的都是需要安装ntfs-3g安装包. 安装完后每次插入移动存储介质时,都需要手动去挂载. 作为一个做技术的,如果不能解决 ...
- 使用Ubuntu手动安装NextCloud
p.p1 { margin: 0; font: 11px Menlo; color: rgba(0, 0, 0, 1) } span.s1 { font-variant-ligatures: no-c ...
- Blogs模板选择及基础代码设置
#1.皮肤选择 #2.页面定制 CSS 代码 @font-face { font-family: 'FontAwesome'; font-style: normal; font-weight: nor ...