MySql慢查询日志——开启/查看/删除
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慢查询日志——开启/查看/删除的更多相关文章
- mysql慢查询日志开启和存储格式
mysql版本号是mysql5.6.22.安装环境windows7. 1.使用该查询日志能够找到有效率问题的sql语句.并记录下来,进行监控. 能够使用例如以下语句查询和设置慢查询日志 (1) 查看慢 ...
- mysql 慢查询日志 mysqldumpslow 工具
文章来源:https://www.cnblogs.com/hello-tl/p/9229676.html 1.使用Mysql慢查询日志配置 查看慢查询日志是否开启 OFF关闭 ON开启 show va ...
- linux上开启和分析mysql慢查询日志
本人qq群也有许多的技术文档,希望可以为你提供一些帮助(非技术的勿加). QQ群: 281442983 (点击链接加入群:http://jq.qq.com/?_wv=1027&k=29Lo ...
- MySQL慢查询日志如何开启以及分析
1.MySQL慢查询日志是什么 (1)MySQL的慢查询日志是MySQL提供的一种日志记录,它用来记录MySQL中查询时间超过(大于)设置阈值(long_query_time)的语句,记录到慢查询日志 ...
- 企业级中带你ELK如何实时收集分析Mysql慢查询日志
什么是Mysql慢查询日志? 当SQL语句执行时间超过设定的阈值时,便于记录到指定的日志文件中或者表中,所有记录称之为慢查询日志 为什么要收集Mysql慢查询日志? 数据库在运行期间,可能会存在这很多 ...
- MySQL慢查询日志
实验环境: OS X EI Captian + MySQL 5.7 一.配置MySQL自动记录慢查询日志 查看变量,也就是配置信息 show (global) variables like '%slo ...
- MySQL 慢查询日志配置与简析
MySQL慢查询日志配置与简析 By:授客 QQ:1033553122 <1> 查看是否开启慢查询日志 SHOW VARIABLES LIKE 'slow%'; 说明: a. 如果sl ...
- MySQL慢查询日志总结 日志分析工具mysqldumpslow
MySQL慢查询日志总结 - 潇湘隐者 - 博客园 https://www.cnblogs.com/kerrycode/p/5593204.html 2016-06-17 10:32 by 潇湘隐者, ...
- mysql慢查询日志功能的使用
作用:mysql慢查询日志可监控有效率问题的SQL .. 一.开启mysql慢查询日志功能 1.查看是否开启 未使用索引的SQL记录日志查询 mysql> show variables like ...
随机推荐
- Ios国际化翻译工具
IOS Translation Tool(IOS国际化翻译工具) 介绍 当IOS项目国际化的时候,手工去翻译每一个字符串是一件非常痛苦的事情.尤其是当项目中存在N多种语言.而且又很难保证,手工翻译的准 ...
- 10、SpringBoot-CRUD登陆拦截
1.前端页面的设置 index.html <input type="text" class="form-control" name="usern ...
- Lambda使用
说明 本文内容来自 [Java8 In Action] 一书 四种方法引用类型 类型 示例 引用静态方法 ContainingClass::staticMethodName 引用某个对象的实例方法 c ...
- 转:javax.net.ssl.SSLHandshakeException: Received fatal alert: handshake_failure 解决方案
转:javax.net.ssl.SSLHandshakeException: Received fatal alert: handshake_failure 解决方案javax.net.ssl.SSL ...
- python调用对象属性出错:AttributeError: 'function' object has no attribute '_name_'
出错如下图所示: 原来是因为把__name__写成_name_, 下图为正确结果:
- Android 第三方应用接入微信平台研究情况分享
微信平台开放后倒是挺火的,许多第三方应用都想试下接入微信这个平台,毕竟可以利用微信建立起来的关系链来拓展自己的应用还是挺不错的 最近由于实习需要也在研究这个东西,这里把我的整个研究情况给出来 微信平台 ...
- LeetCode21.合并两个有序链表 JavaScript
将两个有序链表合并为一个新的有序链表并返回.新链表是通过拼接给定的两个链表的所有节点组成的. 示例: 输入:1->2->4, 1->3->4 输出:1->1->2- ...
- 【2017001】IList转DataTable、DataTable转IList
IList转DataTable.DataTable转IList using System; using System.Collections.Generic; using System.Compone ...
- 竞赛题解 - Broken Tree(CF-758E)
Broken Tree(CF-758E) - 竞赛题解 贪心复习~(好像暴露了什么算法--) 标签:贪心 / DFS / Codeforces 『题意』 给出一棵以1为根的树,每条边有两个值:p-强度 ...
- shell编程基础-01
1.1 前言 1.1.1 为什么学Shell Shell脚本语言是实现Linux/UNIX系统管理及自动化运维所必备的重要工具Linux/UNIX系统的底层及基础应用软件的核心大都涉及Shell脚本的 ...