通过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是怎么样连接表,使用什么方式扫描表(索引扫描或全表扫描)以及 ...
随机推荐
- JQuery统一复写美化项目中所有radio单选按钮样式
老项目要升级改版,对于分散在各页面的样式不好处理,怕有遗漏,尤其是优化input表单,修改其默认样式,接下来,我将给大家分享一下,我在项目中的总结. 效果 上代码: 1.简单搞一搞 CSS,此处代码有 ...
- php项目从github自动pull到服务器
php项目github自动pull到服务器 项目名:web 一.自动触发 1.在服务器添加脚本文件:gitpull.sh #!/bin/sh cd /www/web git reset --hard ...
- Cisco Packet Tracer NAT模拟实验
Cisco Packet Tracer NAT模拟实验 by: 铁乐猫 date: 2020-09-22 cisco packet tracer : 7.2.2 NAT简介 NAT允许将私有IP地址映 ...
- docker 安装es跟kibana
首先docker 查询es docker search elasticsearch 在docker pull elasticsearch:7.9.3 docker在查询 kibana docker ...
- kali docker简单使用-vulhub搭建fastjson漏洞环境
准备环境 安装kali和docker参考: https://www.cnblogs.com/lijingrong/p/13396884.html sudo service docker start / ...
- Python 炫技操作:安装包的八种方法,你知道吗?
本文的文字及图片来源于网络,仅供学习.交流使用,不具有任何商业用途,如有问题请及时联系我们以作处理 1. 使用 easy_install easy_install 这应该是最古老的包安装方式了,目前基 ...
- python多元回归于调用excel文件
import xlrd from numpy.linalg import inv import numpy as np data = xlrd.open_workbook(u'C:\\Users\\x ...
- 初接触matplotlib
1,绘制简单的折线图. 1 import matplotlib.pyplot as plt 2 3 square = [1,4,9,16,25] 4 5 plt.plot(square) 6 plt. ...
- asp.net url参数中有中文request.querystring 乱码
说明: 从这点我们发现:所有的参数输入,都调用了一次:HttpUtility.UrlDecode(str2, encoding); 结论出来了: 当客户端js对中文以utf-8编码提交到服务端时,用R ...
- 深入理解Spring Security授权机制原理
原创/朱季谦 在Spring Security权限框架里,若要对后端http接口实现权限授权控制,有两种实现方式. 一.一种是基于注解方法级的鉴权,其中,注解方式又有@Secured和@PreAuth ...