mysql slow time_mysql使用slow log
1.运行环境:xampp1.7.3,mysql版本为5.1.41
2.开启slow log:
(1)打开d:/xampp/mysql/bin/my.ini,设置
slow_query_log = 1
slow_query_log_file = "d:/xampp/mysql/data/mysql-slow.log"
long_query_time=0//新加
(2)D:\xampp\mysql\data\下新建txt文件mysql-slow.log
(3)重启或启动xampp中apache mysql
注:(2)必须后跟(3),看后面的log记录开头几行就会明白
3.测试:运行脚本(注:仅测试log使用,无die等处理错误)
$h=mysql_connect("localhost",'root','');
mysql_select_db("test",$h);
mysql_query("flush status");
$res=mysql_query("select t1.id from t1 inner join t2 on t1.id=t2.id");
while($r=mysql_fetch_assoc($res)){
var_dump($r);
}
mysql_close($h);
?>
以下是运行该脚本的log记录
D:\xampp\mysql\bin\mysqld.exe, Version: 5.1.41-log (Source distribution). started with:
TCP Port: 3306, Named Pipe: MySQL
Time Id Command Argument
# Time: 111124 15:32:10
# User@Host: root[root] @ localhost [127.0.0.1]
# Query_time: 0.040057 Lock_time: 0.000000 Rows_sent: 4 Rows_examined: 4
use test;
SET timestamp=1322119930;
select t1.id from t1 inner join t2 on t1.id=t2.id;
# Time: 111124 15:33:23
# User@Host: root[root] @ localhost [127.0.0.1]
# Query_time: 0.040058 Lock_time: 0.000000 Rows_sent: 4 Rows_examined: 4
SET timestamp=1322120003;
select t1.id from t1 inner join t2 on t1.id=t2.id;
# Time: 111124 15:33:49
# User@Host: root[root] @ localhost [127.0.0.1]
# Query_time: 0.040058 Lock_time: 0.000000 Rows_sent: 4 Rows_examined: 4
SET timestamp=1322120029;
select t1.id from t1 inner join t2 on t1.id=t2.id;
# Time: 111124 15:34:07
# User@Host: root[root] @ localhost [127.0.0.1]
# Query_time: 0.030044 Lock_time: 0.000000 Rows_sent: 4 Rows_examined: 4
SET timestamp=1322120047;
select t1.id from t1 inner join t2 on t1.id=t2.id;
# Time: 111124 15:34:29
# User@Host: root[root] @ localhost [127.0.0.1]
# Query_time: 0.030043 Lock_time: 0.000000 Rows_sent: 4 Rows_examined: 4
SET timestamp=1322120069;
select t1.id from t1 inner join t2 on t1.id=t2.id;
# Time: 111124 15:34:56
# User@Host: root[root] @ localhost [127.0.0.1]
# Query_time: 0.030044 Lock_time: 0.000000 Rows_sent: 4 Rows_examined: 4
SET timestamp=1322120096;
select t1.id from t1 inner join t2 on t1.id=t2.id;
# Time: 111124 15:34:58
# User@Host: root[root] @ localhost [127.0.0.1]
# Query_time: 0.020029 Lock_time: 0.000000 Rows_sent: 4 Rows_examined: 4
SET timestamp=1322120098;
select t1.id from t1 inner join t2 on t1.id=t2.id;
# User@Host: root[root] @ localhost [127.0.0.1]
# Query_time: 0.040058 Lock_time: 0.000000 Rows_sent: 4 Rows_examined: 4
SET timestamp=1322120098;
select t1.id from t1 inner join t2 on t1.id=t2.id;
4.在my.ini中改long_query_time=0.04,也就是40毫秒,重启xampp,以下是运行脚本的log结果:
D:\xampp\mysql\bin\mysqld.exe, Version: 5.1.41-log (Source distribution). started with:
TCP Port: 3306, Named Pipe: MySQL
Time Id Command Argument
# Time: 111124 15:41:40
# User@Host: root[root] @ localhost [127.0.0.1]
# Query_time: 0.040057 Lock_time: 0.000000 Rows_sent: 4 Rows_examined: 4
use test;
SET timestamp=1322120500;
select t1.id from t1 inner join t2 on t1.id=t2.id;
# Time: 111124 15:41:54
# User@Host: root[root] @ localhost [127.0.0.1]
# Query_time: 0.040058 Lock_time: 0.000000 Rows_sent: 4 Rows_examined: 4
SET timestamp=1322120514;
select t1.id from t1 inner join t2 on t1.id=t2.id;
# Time: 111124 15:41:56
# User@Host: root[root] @ localhost [127.0.0.1]
# Query_time: 0.040058 Lock_time: 0.000000 Rows_sent: 4 Rows_examined: 4
SET timestamp=1322120516;
select t1.id from t1 inner join t2 on t1.id=t2.id;
# Time: 111124 15:41:59
# User@Host: root[root] @ localhost [127.0.0.1]
# Query_time: 0.040057 Lock_time: 0.000000 Rows_sent: 4 Rows_examined: 4
SET timestamp=1322120519;
select t1.id from t1 inner join t2 on t1.id=t2.id;
# User@Host: root[root] @ localhost [127.0.0.1]
# Query_time: 0.040057 Lock_time: 0.000000 Rows_sent: 4 Rows_examined: 4
SET timestamp=1322120519;
select t1.id from t1 inner join t2 on t1.id=t2.id;
# User@Host: root[root] @ localhost [127.0.0.1]
# Query_time: 0.040058 Lock_time: 0.000000 Rows_sent: 4 Rows_examined: 4
SET timestamp=1322120519;
select t1.id from t1 inner join t2 on t1.id=t2.id;
# Time: 111124 15:45:41
# User@Host: root[root] @ localhost [127.0.0.1]
# Query_time: 0.070101 Lock_time: 0.000000 Rows_sent: 4 Rows_examined: 4
SET timestamp=1322120741;
select t1.id from t1 inner join t2 on t1.id=t2.id;
# User@Host: root[root] @ localhost [127.0.0.1]
# Query_time: 0.040057 Lock_time: 0.000000 Rows_sent: 4 Rows_examined: 4
SET timestamp=1322120741;
select t1.id from t1 inner join t2 on t1.id=t2.id;
# Time: 111124 15:45:42
# User@Host: root[root] @ localhost [127.0.0.1]
# Query_time: 0.040058 Lock_time: 0.000000 Rows_sent: 4 Rows_examined: 4
SET timestamp=1322120742;
select t1.id from t1 inner join t2 on t1.id=t2.id;
# User@Host: root[root] @ localhost [127.0.0.1]
# Query_time: 0.040058 Lock_time: 0.000000 Rows_sent: 4 Rows_examined: 4
SET timestamp=1322120742;
select t1.id from t1 inner join t2 on t1.id=t2.id;
# Time: 111124 15:45:43
# User@Host: root[root] @ localhost [127.0.0.1]
# Query_time: 0.040058 Lock_time: 0.000000 Rows_sent: 4 Rows_examined: 4
SET timestamp=1322120743;
select t1.id from t1 inner join t2 on t1.id=t2.id;
5. 在my.ini中改long_query_time=0,重启xampp运行脚本
$h=mysql_connect("localhost",'root','');
mysql_select_db("test",$h);
$res=mysql_query("select t1.id from t1 inner join t2 on t1.id=t2.id");
while($r=mysql_fetch_assoc($res)){
var_dump($r);
}
mysql_close($h);
?>
以下是log结果:
D:\xampp\mysql\bin\mysqld.exe, Version: 5.1.41-log (Source distribution). started with:
TCP Port: 3306, Named Pipe: MySQL
Time Id Command Argument
# Time: 111124 16:00:05
# User@Host: root[root] @ localhost [127.0.0.1]
# Query_time: 0.030043 Lock_time: 0.000000 Rows_sent: 4 Rows_examined: 4
use test;
SET timestamp=1322121605;
select t1.id from t1 inner join t2 on t1.id=t2.id;
# Time: 111124 16:00:27
# User@Host: root[root] @ localhost [127.0.0.1]
# Query_time: 0.040057 Lock_time: 0.000000 Rows_sent: 4 Rows_examined: 4
SET timestamp=1322121627;
select t1.id from t1 inner join t2 on t1.id=t2.id;
# Time: 111124 16:00:28
# User@Host: root[root] @ localhost [127.0.0.1]
# Query_time: 0.040057 Lock_time: 0.000000 Rows_sent: 4 Rows_examined: 4
SET timestamp=1322121628;
select t1.id from t1 inner join t2 on t1.id=t2.id;
# Time: 111124 16:00:45
# User@Host: root[root] @ localhost [127.0.0.1]
# Query_time: 0.010015 Lock_time: 0.000000 Rows_sent: 4 Rows_examined: 4
SET timestamp=1322121645;
select t1.id from t1 inner join t2 on t1.id=t2.id;
# Time: 111124 16:00:46
# User@Host: root[root] @ localhost [127.0.0.1]
# Query_time: 0.010014 Lock_time: 0.000000 Rows_sent: 4 Rows_examined: 4
SET timestamp=1322121646;
select t1.id from t1 inner join t2 on t1.id=t2.id;
# User@Host: root[root] @ localhost [127.0.0.1]
# Query_time: 0.040058 Lock_time: 0.000000 Rows_sent: 4 Rows_examined: 4
SET timestamp=1322121646;
select t1.id from t1 inner join t2 on t1.id=t2.id;
# Time: 111124 16:00:47
# User@Host: root[root] @ localhost [127.0.0.1]
# Query_time: 0.020029 Lock_time: 0.000000 Rows_sent: 4 Rows_examined: 4
SET timestamp=1322121647;
select t1.id from t1 inner join t2 on t1.id=t2.id;
# Time: 111124 16:00:48
# User@Host: root[root] @ localhost [127.0.0.1]
# Query_time: 0.040058 Lock_time: 0.000000 Rows_sent: 4 Rows_examined: 4
SET timestamp=1322121648;
select t1.id from t1 inner join t2 on t1.id=t2.id;
# User@Host: root[root] @ localhost [127.0.0.1]
# Query_time: 0.040058 Lock_time: 0.000000 Rows_sent: 4 Rows_examined: 4
SET timestamp=1322121648;
select t1.id from t1 inner join t2 on t1.id=t2.id;
# User@Host: root[root] @ localhost [127.0.0.1]
# Query_time: 0.020029 Lock_time: 0.000000 Rows_sent: 4 Rows_examined: 4
SET timestamp=1322121648;
select t1.id from t1 inner join t2 on t1.id=t2.id;
# Time: 111124 16:00:49
# User@Host: root[root] @ localhost [127.0.0.1]
# Query_time: 0.010014 Lock_time: 0.000000 Rows_sent: 4 Rows_examined: 4
SET timestamp=1322121649;
select t1.id from t1 inner join t2 on t1.id=t2.id;
# Time: 111124 16:00:50
# User@Host: root[root] @ localhost [127.0.0.1]
# Query_time: 0.020029 Lock_time: 0.000000 Rows_sent: 4 Rows_examined: 4
SET timestamp=1322121650;
select t1.id from t1 inner join t2 on t1.id=t2.id;
该份脚本比3和4运行的脚本少了mysql_query("flush status");,看log记录可以看到该份脚本运行有不少0.01和0.02秒的记录,这也能看出mysql自身的缓存也加快了select的速度!
mysql slow time_mysql使用slow log相关推荐
- mysql数据库重做日志文件_数据库:mysql:重做日志文件(redo log file)
一.重做日志缓冲(redo log buffer) 1. log block 在InnoDB存储引擎中,重做日志都是以512字节进行存储的.这意味着重做日志缓存.重做日志文件都是以块(block)的方 ...
- MySQL slowlog 统计_mysql slow log 简单统计
众所周知,mysql slow log中很多sql语句结构和对象是相同,只是其中变量不一样,对于这样的sql,我们完全可以将其归为一类,统计其执行次数.执行时间平均值等参数,而pt-query-dig ...
- mysql slow设置_mysql slow log设置
1.mysql slow query log参数设置 首先简单的介绍一下如何开启mysql的slowlog,主要设置一下几个参数: 1)–slow_query_log = 1,开启slowlog. 2 ...
- mysql slow query_Mysql 开启 Slow 慢查询
1:登录数据库查看是否已经开启了Slow慢查询: mysql> show variables like 'slow_query%'; 2:开启Mysql slow日志: 默认情况下slow_qu ...
- 精讲 MySQL 事务日志:redo log 和 undo log
来源:https://blog.csdn.net/demonson/article/details/104369733 innodb事务日志包括redo log和undo log.redo log是重 ...
- 3、MySQL二进制日志(Binary Log)详解
二进制日志(Binary Log)也可叫作变更日志(Update Log),是 MySQL 中非常重要的日志.主要用于记录数据库的变化情况,即 SQL 语句的 DDL 和 DML 语句,不包含数据记录 ...
- 2、MySQL错误日志(Error Log)详解
错误日志(Error Log)是 MySQL 中最常用的一种日志,主要记录 MySQL 服务器启动和停止过程中的信息.服务器在运行过程中发生的故障和异常情况等. 作为初学者,要学会利用错误日志来定位问 ...
- MySQL深度剖析之undo log redo log binlog专题(2021)
因为每次对磁盘随机读写影响性能,尤其是高并发的时候,所以引入了Buffer Pool, 即只要更新Buffer Pool中的记录,则算更新成功,那如果更新完了还没有flush到磁盘则宕机了,此时内存的 ...
- mysql重做日志_详解MySQL 重做日志(redo log)与回滚日志(undo logo)
前言: 前面文章讲述了 MySQL 系统中常见的几种日志,其实还有事务相关日志 redo log 和 undo log 没有介绍.相对于其他几种日志而言, redo log 和 undo log 是更 ...
最新文章
- 探秘网络背后黑产链:黑客攻击木马病毒机构内鬼防不胜防
- 双向多点路由重分布--如何防止路由环路以及次优路径
- rpm包时遇到Header V3 DSA signature: NOKEY时解决办法
- 别问我跨域了,我想吐
- python------面向对象介绍
- c#串口程序接收数据并打印_C#程序可打印各种数据类型的大小
- python图像数据是几维数据_python实现读取类别频数数据画水平条形图案例
- (一) Qt Model/View 的简单说明
- Linux就该这么学-第三课
- php文件包含漏洞的危害,php文件包含漏洞小结
- 大数据技术平台主要分为哪几类
- 世界大了,啥子都有,全球最大中文搜"人"引擎
- Material Design使用集合
- Weka中数据挖掘与机器学习系列之Weka系统安装(四)
- android读取主板数据恢复,重磅干货!高通9008模式与数据提取用于恢复数据
- web安全day19:DNS欺骗、ARP攻击及钓鱼网站制作
- 【0226】信息安全与密码技术
- 阳春三月,再送32本书,快来快来!
- 光猫路由器一体机安装和千兆网络
- apache 的配置文件hthp.conf里边都是什么意思?
热门文章
- ubuntu修改启动为文本模式
- 小白初学搭建 配置本地yum
- 关于js中window.location.href,location.href,parent.location.href,top.location.href的使用方法
- Yii中的CComponent应用实例
- Socket网络编程--聊天程序(3)
- oracle 与sql serve 获取随机行数的数据
- 使用SmsManager服务群发短信
- ProEssentials实时三维图表控件
- id_Tech5_challenges--siggraph09
- linux 暂停一段时间,sleep命令_Linux sleep命令:让程序暂停或休眠一段时间