1,开启慢查询日志

修改mysql.ini文件,加入如下配置:

[mysqld]
log-slow-queries=H:\mysql_log\slow_query.log
long-query-time=3

set global slow_query_log=ON;

set global slow_launch_time=5;

show variables like "%slow%";

设置查询日志的存储位置,慢查询时间。

show variables like '%slow%'; /*查看慢查询配置*/

show variables like "long_query_time"; /*查看慢查询时间*/

show status like "%slow_queries%";/*查看慢查询配置情况*/

2,查看慢查询

打开log文件:

F:\mysql\bin\mysqld, Version: 5.5.24-log (MySQL Community Server (GPL)). started with:
TCP Port: 3306, Named Pipe: (null)
Time                 Id Command    Argument
# Time: 161008 21:20:02
# User@Host: root[root] @ localhost [127.0.0.1]
# Query_time: 8.718499  Lock_time: 0.001002 Rows_sent: 0  Rows_examined: 908972
use energy;
SET timestamp=1475932802;
/*结束时间*/

select 

DATE_FORMAT(worker_order.create_time,'%Y-%m-%d') as create_time,/*创建时间*/
(	select count(0)
		from biz_work_order tmp
		where
		DATE_FORMAT(tmp.create_time,'%Y-%m-%d')=DATE_FORMAT(worker_order.create_time,'%Y-%m-%d')
		or (tmp.create_time<DATE_FORMAT(worker_order.create_time,'%Y-%m-%d') and tmp.`status` in (1,2,4))
	)as should_change_worker_order

from biz_work_order worker_order 

WHERE
				(CASE  WHEN IFNULL(@belongCity,'0')='0' OR @belongCity=''  THEN  1 ELSE   

        CAST(LOCATE(@belongCity,worker_order.belong_city) AS SIGNED )   

        END)=1
AND

	(CASE  WHEN IFNULL(@energyStation,'0')='0'  THEN  1 ELSE   

        CAST(LOCATE(@energyStation,worker_order.repository_id) AS SIGNED )   

        END)=1
AND
	(CASE  WHEN IFNULL(@serviceStatioin,'0')='0'  THEN  1 ELSE   

        CAST(LOCATE(@serviceStatioin,worker_order.station_id) AS SIGNED )   

        END)=1
AND
				DATE_FORMAT(worker_order.create_time, '%Y-%m-%d') BETWEEN DATE_FORMAT(cast(@beginDateTime as datetime), '%Y-%m-%d') and DATE_FORMAT(cast(@endDateTime as datetime), '%Y-%m-%d')

GROUP BY DATE_FORMAT(worker_order.create_time,'%Y-%m-%d');
# Time: 161008 21:20:40
# User@Host: root[root] @ localhost [127.0.0.1]
# Query_time: 33.695952  Lock_time: 0.000000 Rows_sent: 0  Rows_examined: 3239812
SET timestamp=1475932840;
/*结束时间*/

select 

DATE_FORMAT(worker_order.create_time,'%Y-%m-%d') as create_time,/*创建时间*/
(	select count(0)
		from biz_work_order tmp
		where
		DATE_FORMAT(tmp.create_time,'%Y-%m-%d')=DATE_FORMAT(worker_order.create_time,'%Y-%m-%d')
		or (tmp.create_time<DATE_FORMAT(worker_order.create_time,'%Y-%m-%d') and tmp.`status` in (1,2,4))
	)as should_change_worker_order

from biz_work_order worker_order 

WHERE
				(CASE  WHEN IFNULL(@belongCity,'0')='0' OR @belongCity=''  THEN  1 ELSE   

        CAST(LOCATE(@belongCity,worker_order.belong_city) AS SIGNED )   

        END)=1
AND

	(CASE  WHEN IFNULL(@energyStation,'0')='0'  THEN  1 ELSE   

        CAST(LOCATE(@energyStation,worker_order.repository_id) AS SIGNED )   

        END)=1
AND
	(CASE  WHEN IFNULL(@serviceStatioin,'0')='0'  THEN  1 ELSE   

        CAST(LOCATE(@serviceStatioin,worker_order.station_id) AS SIGNED )   

        END)=1
AND
				DATE_FORMAT(worker_order.create_time, '%Y-%m-%d') BETWEEN DATE_FORMAT(cast(@beginDateTime as datetime), '%Y-%m-%d') and DATE_FORMAT(cast(@endDateTime as datetime), '%Y-%m-%d')

GROUP BY DATE_FORMAT(worker_order.create_time,'%Y-%m-%d');
# Time: 161008 21:21:49
# User@Host: root[root] @ localhost [127.0.0.1]
# Query_time: 48.615826  Lock_time: 0.000000 Rows_sent: 0  Rows_examined: 4920668
SET timestamp=1475932909;
/*结束时间*/

select 

DATE_FORMAT(worker_order.create_time,'%Y-%m-%d') as create_time,/*创建时间*/
(	select count(0)
		from biz_work_order tmp
		where
		DATE_FORMAT(tmp.create_time,'%Y-%m-%d')=DATE_FORMAT(worker_order.create_time,'%Y-%m-%d')
		or (tmp.create_time<DATE_FORMAT(worker_order.create_time,'%Y-%m-%d') and tmp.`status` in (1,2,4))
	)as should_change_worker_order

from biz_work_order worker_order 

WHERE
				(CASE  WHEN IFNULL(@belongCity,'0')='0' OR @belongCity=''  THEN  1 ELSE   

        CAST(LOCATE(@belongCity,worker_order.belong_city) AS SIGNED )   

        END)=1
AND

	(CASE  WHEN IFNULL(@energyStation,'0')='0'  THEN  1 ELSE   

        CAST(LOCATE(@energyStation,worker_order.repository_id) AS SIGNED )   

        END)=1
AND
	(CASE  WHEN IFNULL(@serviceStatioin,'0')='0'  THEN  1 ELSE   

        CAST(LOCATE(@serviceStatioin,worker_order.station_id) AS SIGNED )   

        END)=1
AND
				DATE_FORMAT(worker_order.create_time, '%Y-%m-%d') BETWEEN DATE_FORMAT(cast(@beginDateTime as datetime), '%Y-%m-%d') and DATE_FORMAT(cast(@endDateTime as datetime), '%Y-%m-%d')

GROUP BY DATE_FORMAT(worker_order.create_time,'%Y-%m-%d');
# Time: 161008 21:22:37
# User@Host: root[root] @ localhost [127.0.0.1]
# Query_time: 41.309375  Lock_time: 0.000000 Rows_sent: 0  Rows_examined: 6050268
SET timestamp=1475932957;
call Pro_query_work_order_report('50010',NULL,270,date_sub(curdate(), INTERVAL 6 DAY),curdate());
# Time: 161008 21:23:59
# User@Host: root[root] @ localhost [127.0.0.1]
# Query_time: 79.538506  Lock_time: 0.000000 Rows_sent: 7  Rows_examined: 12282968
SET timestamp=1475933039;
call Pro_query_work_order_report('50010',NULL,270,date_sub(curdate(), INTERVAL 6 DAY),curdate());

被自己写的SQL慢哭了。。。

三,删除慢查询日志

直接delete掉log,删除后需要执行下面两句中的任意一句,重新生成日志文件:

  -> mysqladmin -u root-p flush-logs
    -> flush logs

MySql慢查询日志——开启/查看/删除的更多相关文章

  1. mysql慢查询日志开启和存储格式

    mysql版本号是mysql5.6.22.安装环境windows7. 1.使用该查询日志能够找到有效率问题的sql语句.并记录下来,进行监控. 能够使用例如以下语句查询和设置慢查询日志 (1) 查看慢 ...

  2. mysql 慢查询日志 mysqldumpslow 工具

    文章来源:https://www.cnblogs.com/hello-tl/p/9229676.html 1.使用Mysql慢查询日志配置 查看慢查询日志是否开启 OFF关闭 ON开启 show va ...

  3. linux上开启和分析mysql慢查询日志

    本人qq群也有许多的技术文档,希望可以为你提供一些帮助(非技术的勿加). QQ群:   281442983 (点击链接加入群:http://jq.qq.com/?_wv=1027&k=29Lo ...

  4. MySQL慢查询日志如何开启以及分析

    1.MySQL慢查询日志是什么 (1)MySQL的慢查询日志是MySQL提供的一种日志记录,它用来记录MySQL中查询时间超过(大于)设置阈值(long_query_time)的语句,记录到慢查询日志 ...

  5. 企业级中带你ELK如何实时收集分析Mysql慢查询日志

    什么是Mysql慢查询日志? 当SQL语句执行时间超过设定的阈值时,便于记录到指定的日志文件中或者表中,所有记录称之为慢查询日志 为什么要收集Mysql慢查询日志? 数据库在运行期间,可能会存在这很多 ...

  6. MySQL慢查询日志

    实验环境: OS X EI Captian + MySQL 5.7 一.配置MySQL自动记录慢查询日志 查看变量,也就是配置信息 show (global) variables like '%slo ...

  7. MySQL 慢查询日志配置与简析

    MySQL慢查询日志配置与简析 By:授客 QQ:1033553122   <1> 查看是否开启慢查询日志 SHOW VARIABLES LIKE 'slow%'; 说明: a. 如果sl ...

  8. MySQL慢查询日志总结 日志分析工具mysqldumpslow

    MySQL慢查询日志总结 - 潇湘隐者 - 博客园 https://www.cnblogs.com/kerrycode/p/5593204.html 2016-06-17 10:32 by 潇湘隐者, ...

  9. mysql慢查询日志功能的使用

    作用:mysql慢查询日志可监控有效率问题的SQL .. 一.开启mysql慢查询日志功能 1.查看是否开启 未使用索引的SQL记录日志查询 mysql> show variables like ...

随机推荐

  1. Java反编译工具Jad及插件JadClipse配置教程

    Jad是一个Java的一个反编译工具,和eclipse的插件JadClipse,二者结合可以方便的在eclipse中查看class文件的源代码. 下面介绍一下配置: 下载JadClipse,http: ...

  2. 智能机器人“小昆”的实现(五)MainActivty的实现及项目结束

    好了,一切准备工作都完成了,下面我们就可以真正的编写MainActivity了.在MainActivity中,我们要为ListView设定适配器,并为发送按钮设定点击事件.我们的逻辑就是点击发送按钮, ...

  3. UIView的多重属性

    1)几何属性: 2)位图属性:

  4. shiro简单入门介绍

    shiro是apache的一个java安全框架 可以完成认证,授权,加密,会话管理,基于web继承,缓存等 功能简介: 从外部来看: shiro架构  Subject:主体,代表了当前“用户”,这个用 ...

  5. webservice和wcf和web.api简单介绍

    转自:无废话的wcf等等 在.net平台下,有大量的技术让你创建一个HTTP服务,像Web Service,WCF,现在又出了Web API.在.net平台下,你有很多的选择来构建一个HTTP Ser ...

  6. MySQL常用API函数

    -- 返回数字的绝对值 SELECT ABS(-10) -- 返回不大于X的最大整数值 SELECT FLOOR(10.9) -- 返回不小于X的最大整数值 SELECT CEILING(10.4) ...

  7. TensorFlow创建简单的图片分类系统--机器学习

    TensorFlow 参考链接 http://www.wolfib.com/Image-Recognition-Intro-Part-1/ 环境要求 linux amd64(必须是64位处理器)pyt ...

  8. 第25章 串行FLASH文件系统FatFs

    25.1  文件系统 即使读者可能不了解文件系统,读者也一定对“文件”这个概念十分熟悉.数据在PC上是以文件的形式储存在磁盘中的,这些数据的形式一般为ASCII码或二进制形式.在上一章我们已经写好了Q ...

  9. 第23章 I2C—读写EEPR

    本章参考资料:<STM32F76xxx参考手册>.<STM32F7xx规格书>.库帮助文档<STM32F779xx_User_Manual.chm>及<I2C ...

  10. Advanced Plugin Concepts

    Provide Public Access to Default Plugin Settings An improvement we can, and should, make to the code ...