http://dev.mysql.com/doc/refman/5.0/en/slow-query-log.html
ld_safe &试试看我整理的笔记
1. 安装mysql
mysql-5.0.41-linux-i686-glibc23.tar.gz 由于mysql是二进制包。所以还是比较方便的。
直接解压。然后移动。
mv mysql-5.0.41-linux-x86_64-glibc23 /usr/local/mysql
cd /usr/local/mysql
groupadd mysql
useradd -g mysql mysql
chown -R mysql .
chgrp -R mysql .
chown -R root .
./scripts/mysql_install_db --user=mysql --basedir=/usr/local/mysql --datadir=/home/www/mysql/data
cp /usr/local/mysql/support-files/my-huge.cnf /etc/my.cnf
cp /usr/local/mysql/support-files/mysql.server /etc/rc.d/init.d/mysqld
chmod 755 /etc/rc.d/init.d/mysqld
chkconfig –add mysqld
chkconfig --level 3 mysqld on
mv /usr/local/mysql/data /home/www/mysql
chown -R mysql:mysql /home/www/mysql
编辑/etc/my.cnf
在 [mysqld] 段增加
datadir = /home/www/mysql
skip-innodb
wait-timeout = 10
max_connections = 512
max_connect_errors = 10000000
在 [mysqld] 段修改
max_allowed_packet = 16M
thread_cache_size = CPU个数*2
将 log-bin 注释
service mysqld start
bin/mysqladmin -u root -p
一.错误日志错误日志在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: Startedlog 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 completedlog 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: Startedlog 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
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)