开启profile优化SQL语句:
set profiling=1;
执行SQL语句
show profiles;
show profile for query 2;//根据query_id 查看某个查询的详细时间耗费

SHOW STATUS LIKE 'last_query_cost';//查询上一条语句执行的代价

例:

mysql> show profiles;
+----------+------------+----------------------------------------+
| Query_ID | Duration   | Query                                  |
+----------+------------+----------------------------------------+
|        1 | 0.00049325 | select * from t_1_waybill              |
|        2 | 0.00130650 | select SQL_NO_CACHE * from t_1_waybill |
|        3 | 0.05051650 | show profiles for query 2              |
+----------+------------+----------------------------------------+
3 rows in set (0.00 sec)

mysql> show profile for query 1;
+--------------------------------+----------+
| Status                         | Duration |
+--------------------------------+----------+
| starting                       | 0.000032 |
| checking query cache for query | 0.000010 |
| checking privileges on cached  | 0.000010 |
| sending cached result to clien | 0.000435 |
| logging slow query             | 0.000004 |
| cleaning up                    | 0.000003 |
+--------------------------------+----------+
6 rows in set (0.00 sec)

mysql> show profile for query 2;
+--------------------+----------+
| Status             | Duration |
+--------------------+----------+
| starting           | 0.000159 |
| Opening tables     | 0.000034 |
| System lock        | 0.000005 |
| Table lock         | 0.000017 |
| init               | 0.000051 |
| optimizing         | 0.000004 |
| statistics         | 0.000019 |
| preparing          | 0.000009 |
| executing          | 0.000002 |
| Sending data       | 0.000607 |
| end                | 0.000006 |
| query end          | 0.000008 |
| freeing items      | 0.000364 |
| logging slow query | 0.000006 |
| cleaning up        | 0.000017 |
+--------------------+----------+
15 rows in set (0.00 sec)

通过profile优化SQL语句的更多相关文章

  1. 应用索引技术优化SQL 语句(转)

    原文出处 一.前言 很多数据库系统性能不理想是因为系统没有经过整体优化,存在大量性能低下的SQL 语句.这类SQL语句性能不好的首要原因是缺乏高效的索引.没有索引除了导致语句本身运行速度慢外,更是导致 ...

  2. MySql(五)SQL优化-优化SQL语句的一般步骤

    MySql(五)SQL优化-优化SQL语句的一般步骤 一.优化SQL语句的一般步骤 1.1 通过show status命令了解各种SQL的执行频率 1.2 定位执行效率较低的SQL语句 1.3 通过e ...

  3. mysql优化SQL语句的一般步骤及常用方法

    一.优化SQL语句的一般步骤 1. 通过show status命令了解各种SQL的执行频率 mysqladmin extended-status 或: show [session|global]sta ...

  4. MySQL查询不使用索引汇总 + 如何优化sql语句

    不使用索引原文 : http://itlab.idcquan.com/linux/MYSQL/918330.html MySQL查询不使用索引汇总 众所周知,增加索引是提高查询速度的有效途径,但是很多 ...

  5. 8.2.优化SQL语句

    8.2.优化SQL语句 数据库应用程序核心操作逻辑都是通过执行SQL语句来执行,不管是直接通过解释器还是通过后台API提交. 调优手册里面的这一节内容帮助各种各样MySQL程序加快速度.手册包括SQL ...

  6. 浅谈MySQL中优化sql语句查询常用的30种方法 - 转载

    浅谈MySQL中优化sql语句查询常用的30种方法 1.对查询进行优化,应尽量避免全表扫描,首先应考虑在 where 及 order by 涉及的列上建立索引. 2.应尽量避免在 where 子句中使 ...

  7. mysql优化sql语句

    mysql优化sql语句   常见误区   www.2cto.com   误区1:   count(1)和count(primary_key) 优于 count(*)   很多人为了统计记录条数,就使 ...

  8. 优化 SQL 语句的步骤

    优化 SQL 语句的步骤 1.分析MySQL服务器当前的状态信息 SHOW SESSION STATUS; SHOW SESSION STATUS LIKE 'Com_%' //当前会话下所有语句类型 ...

  9. Oracle 通过sql profile为sql语句加hint

    sql profile最大的优点是在不修改sql语句和会话执行环境的情况下去优化sql的执行效率,适合无法在应用程序中修改sql时.sql profile最常用方法大概是:--创建产生sql tuni ...

随机推荐

  1. 查看tensorflow版本和存储位置

    >>>import tensorflow as tf >>>tf.__version__ __是两个下划线,中间有空格 >>>tf.__path_ ...

  2. Android 4.4 全套源代码及子模块源代码的下载方法

    博文<Android源代码下载--用git clone实现单个文件夹下载>介绍了採用git clone方法下载Android单个文件夹源代码的方法,这篇文章已经有四年的历史,这期间Goog ...

  3. python模块学习之six模块

    Six:Python 2和3兼容性库 Six提供了简单的实用程序,用于覆盖Python 2和Python 3之间的差异.它旨在支持在Python 2和3中都可以进行修改的代码库. 六个只包含一个Pyt ...

  4. iOS swift cookie创建存储移除

    保存网络请求的cookies,并存储到UserDefaults中 //保存COOKIES static func saveCookies(for urlStr: String){ if let url ...

  5. imx6 uboot启动流程分析

    参考http://blog.csdn.net/skyflying2012/article/details/25804209 这里以imx6平台为例,分析uboot启动流程对于任何程序,入口函数是在链接 ...

  6. VM603:1 Uncaught SyntaxError: Unexpected token o in JSON at position 1

    再用JQuery解析json的时候出现了这样一个问题 VM603: Uncaught SyntaxError: Unexpected token o 通过查阅资料发现,是由于解析json文件的时候解析 ...

  7. abp主机用户不过滤租户id

    using (_unitOfWorkManager.Current.DisableFilter(DataFilterUtil.NowDisableFilter(AbpSession))) { var ...

  8. 基于docker的webrtc开发环境

    在root目录下先放好自定义的constants.py文件再docker run 同时记得修改PUBLIC_IP 可以跨wifi通信 docker pull piasy/apprtc-server d ...

  9. tp 大致执行流程

    http://www.thinkphp.cn/code/305.html http://document.thinkphp.cn/manual_3_2.html#wechat

  10. web开发之php--- mvc 模式

    http://www.cnblogs.com/archy_yu/p/4229929.html