通过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是怎么样连接表,使用什么方式扫描表(索引扫描或全表扫描)以及 ...
随机推荐
- Day3 条件判断和循环
条件判断 if...else if...elif...else 格式: 注意缩进! if x: active elif y: active else : active 注 ...
- curl使用技巧汇总
1,curl 忽略证书安全验证 curl https://192.168.1.5:8443-insecure -I
- Spark-2-性能监控方式
1 Spark Web UI Spark提供了一些基本的Web监控页面,对于日常监控十分有用. 通过http://master:4040(默认端口是4040,可以通过spark.ui.port修改)我 ...
- 配合php伪协议利用文件包含漏洞
文章来源: https://blog.csdn.net/zpy1998zpy/article/details/80598768?utm_medium=distribute.pc_relevant.no ...
- 基于SpringBoot+Mybatis+MySQL5.7的轻语音乐网
一个基于SpringBoot+Mybatis+MySQL5.7的轻语音乐网站项目 1.主要用到的技术: 使用maven进行项目构建 使用Springboot+Mybatis搭建整个系统 使用ajax连 ...
- Python十大装B语法!你会几种?
本文的文字及图片来源于网络,仅供学习.交流使用,不具有任何商业用途,如有问题请及时联系我们以作处理 Python 是一种代表简单思想的语言,其语法相对简单,很容易上手.不过,如果就此小视 Python ...
- python的常用内建模块与常用第三方模块
本文的文字及图片来源于网络,仅供学习.交流使用,不具有任何商业用途,如有问题请及时联系我们以作处理 一.常用内置模块1.datetimePython 提供了一个 time 和 calendar 模块可 ...
- Visual Studio 2013中安装Resharper之后一些快捷键无法使用,比如F6和F12
快捷键是一个很好用的东西,尤其对于计算机从业者来说,好的快捷键能够高程度提高工作效率.像我们程序员经常需要团队开发,我们会遇到一个问题,那就是快捷键不一致问题,我一般会安装resharper,但是有的 ...
- bootstrap(一)栅格系统
中文网:http://www.bootcss.com/ 官网:http://v3.bootcss.com/ 需要准备:离线手册 和 软件包 项目中引用bootstrap.min.js压缩版和boo ...
- python初学者-判断今天是今年的第几天代码
判断今天是今年的第几天源代码 import time date =time.localtime() year,month,day=date[:3] day_month=[31,28,31,30,31, ...