mysql查看数据库的日志文件_怎么查看mysql数据库的日志文件

2017-10-16 回答

一.错误日志

错误日志在mysql数据库中很重要,它记录着mysqld启动和停止,以及服务器在运行过程中发生的任何错误的相关信息。

1.配置信息

--log-error=[file-name]用来指定错误日志存放的位置。

如果没有指定[file-name],默认hostname.err做为文件名,默认存放在datadir目录中。

也可以将log-error配置到my.cnf文件中,这样就省去了每次在启动mysqld时都手工指定--log-error.例如:

[mysql@test2]$ vi /etc/my.cnf

# the mysql server

[mysqld]

....

log-error = /var/lib/mysql/test2_mysqld.err

.....

2.错误信息样板

080313 05:21:55 mysqld started

080313 5:21:55 innodb: started; log sequence number 0 43655

080313 5:21:55 [note] /usr/local/mysql/bin/mysqld: ready for connections.

version: '5.0.26-standard-log' socket: '/var/lib/mysql/mysql.sock' port: 3306 mysql community edition - standard (gpl)

080313 5:24:13 [note] /usr/local/mysql/bin/mysqld: normal shutdown

080313 5:24:13 innodb: starting shutdown...

080313 5:24:16 innodb: shutdown completed; log sequence number 0 43655

080313 5:24:16 [note] /usr/local/mysql/bin/mysqld: shutdown complete

080313 05:24:16 mysqld ended

080313 05:24:47 mysqld started

080313 5:24:47 innodb: started; log sequence number 0 43655

080313 5:24:47 [note] /usr/local/mysql/bin/mysqld: ready for connections.

version: '5.0.26-standard-log' socket: '/var/lib/mysql/mysql.sock' port: 3306 mysql community edition - standard (gpl)

080313 5:33:49 [note] /usr/local/mysql/bin/mysqld: normal shutdown

三.查询日志

查询日志记录了clinet的所有的语句。

note:由于log日志记录了数据库所有操作,对于访问频繁的系统,此种日志会造成性能影响,建议关闭。

1.配置信息

--log=[file-name]用来指定错误日志存放的位置。

如果没有指定[file-name],默认为主机名(hostname)做为文件名,默认存放在datadir目录中。

也可以将log配置到my.cnf文件中,这样就省去了每次在启动mysqld时都手工指定--log.例如:

# the mysql server

[mysqld]

......

#query-log

log = /var/lib/mysql/query_log.log

......

2.读取查询日志

查询日志是纯文本格可,可以使用os文本读取工具直接打开查看。例如:

[mysql@test2]$ tail -n 15 query_log.log

080313 7:58:28 17 query show tables

080313 8:07:45 17 quit

080313 10:01:48 18 connect root@localhost on

080313 10:02:38 18 query select database()

18 init db test

080313 10:02:42 18 query show tables

080313 10:03:07 18 query select * from pet

080313 10:06:26 18 query insert into pet values('hunter','yxyup','cat','f','1996-04-29',null)

080313 10:06:39 18 query select * from pet

080313 10:07:13 18 query update pet set sex='m' where name='hunter'

080313 10:07:38 18 query delete from pet where name='hunter'

080313 10:13:48 18 query desc test8

080313 10:14:13 18 query create table t1(id int,name char(10))

080313 10:14:41 18 query alter table t1 add sex char(2)

[mysql@test2]$

四.慢查询日志

慢查询日志是记录了执行时间超过参数long_query_time(单位是秒)所设定值的sql语句日志。

note:慢查询日志对于我们发现性能有问题的sql有很帮助,建议使用并经常分析

1.配置信息

--log-slow-queries=[file-name]用来指定错误日志存放的位置。

如果没有指定[file-name],默认为hostname-slow.log做为文件名,默认存放在datadir目录中。

也可以将log-slow-queries配置到my.cnf文件中,这样就省去了每次在启动mysqld时都手工指定--log-slow-queries.例如:

# the mysql server

[mysqld]

......

#slow-query-log

log-slow-queries = /var/lib/mysql/slow_query_log.log

......

2.读取慢查询日志

[mysql@test2]$ cat slow_query_log.log

/usr/local/mysql/bin/mysqld, version: 5.0.26-standard-log. started with:

tcp port: 3306 unix socket: /var/lib/mysql/mysql.sock

time id command argument

# time: 080313 5:41:46

# user@host: root[root] @ localhost []

# query_time: 108 lock_time: 0 rows_sent: 0 rows_examined: 8738

use test;

select count(1) from t1 a, t1 b,t1 c where a.id=b.id and b.name=c.name;

# time: 080313 5:52:04

# user@host: root[root] @ localhost []

# query_time: 583 lock_time: 0 rows_sent: 0 rows_examined: 508521177

select count(1) from t1 a, t1 b where a.id=b.id;

/usr/local/mysql/bin/mysqld, version: 5.0.26-standard-log. started with:

tcp port: 3306 unix socket: /var/lib/mysql/mysql.sock

time id command argument

# time: 080313 10:39:59

# user@host: root[root] @ localhost []

# query_time: 11 lock_time: 0 rows_sent: 4537467 rows_examined: 4537467

use test;

select id from tail;

如果慢查询日志记录很多可以使用mysqldumpslow进行分类汇总

[mysql@test2]$ mysqldumpslow slow_query_log.log

reading mysql slow query log from slow_query_log.log

count: 1 time=583.00s (583s) lock=0.00s (0s) rows=0.0 (0), root[root]@localhost

select count(n) from t1 a, t1 b where a.id=b.id

count: 1 time=108.00s (108s) lock=0.00s (0s) rows=0.0 (0), root[root]@localhost

select count(n) from t1 a, t1 b,t1 c where a.id=b.id and b.name=c.name

count: 1 time=11.00s (11s) lock=0.00s (0s) rows=4537467.0 (4537467), root[root]@localhost

select id from tail;

mysql有以下几种日志:

错误日志: -log-err

查询日志: -log

慢查询日志: -log-slow-queries

更新日志: -log-update

二进制日志: -log-bin

在mysql的安装目录下,打开my.ini,在后面加上上面的参数,保存后重启mysql服务就行了。

例如:

#enter a name for the binary log. otherwise a default name will be used.

#log-bin=

#enter a name for the query log file. otherwise a default name will be used.

#log=

#enter a name for the error log file. otherwise a default name will be used.

log-error=

#enter a name for the update log file. otherwise a default name will be used.

#log-update=

查看日至:

1. 首先确认你日志是否启用了

mysql>show variables like 'log_bin';

如果启用了,即on

那日志文件就在mysql的安装目录的data目录下

cat/tail 日志文件名

2. 怎样知道当前的日志

mysql> show master status;

3. 查看从某一段时间到某一段时间的日志

mysqlbinlog --start-datetime='2008-01-19 00:00:00'

--stop-datetime='2008-01-30 00:00:00' /var/log/mysql/mysql-bin.000006

> mysqllog1.log

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值