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. codeforces793 B. Igor and his way to work (dfs)

    题目链接:codeforces793 B. Igor and his way to work (dfs) 求从起点到终点转方向不超过两次是否有解,,好水啊,感觉自己代码好搓.. #include< ...

  2. 对HandlerExecutionChain类的理解分析

    HandlerExecutionChain类比较简单,好理解. ==================================================================== ...

  3. MSF入侵安卓手机

    MSF是Metasploit的简称,Metasploit是一款开源的安全漏洞检测工具,非常强大,分别有Windows版和Linux版,工具里集成了许多微软公布的漏洞(0day). 我这里做测试的系统是 ...

  4. 使用Nginx 做负载均衡

    Nginx可以作为一个非常高效的负载均衡系统,通过分发HTTP请求到多个应用服务器来提高整个系统的吞吐量,性能和可用性. 负载均衡的算法/机制 下面是Nginx支持的机制 轮询机制 轮询算法 最少连接 ...

  5. Servlet是线程安全的吗

    Servlet默认是单例模式,在web容器中只创建一个实例,所以多个线程同时访问Servlet是不安全的. 解决此类问题的办法是: 只要Servlet实现 SingleThreadModel 接口

  6. POJ 1949 Chores (很难想到的dp)

    传送门: http://poj.org/problem?id=1949 Chores Time Limit: 3000MS   Memory Limit: 30000K Total Submissio ...

  7. Mobile IP

    Mobile IP Proliferation(增生) of mobile devices: PDAs, laptops, smart phones, - As user moves, point-o ...

  8. iOS/Swift Tips 1

    1.重写hitTest方法,干预iOS事件传递过程 如下所示,view上有一个button,button一半的frame在父类view bounds之外, 按照iOS系统默认的处理逻辑, 如果点击按钮 ...

  9. c/c++面试指导---c语法总结

    任何一门学科或者专业在学习的过程中都要把握总结框架,大家在面试c/c++职位过程中要应对各种企业的面试,回答企业面试官的各种技术问题.如何应对各种各样的关于c/c++的企业面试题目,从各种繁杂的题目中 ...

  10. chromium之lazy_instance

    先看看介绍 // The LazyInstance<Type, Traits> class manages a single instance of Type, // which will ...