mysql慢查询日志分割:
MySQL缺省提供了一个rotate的参考配置文件,在mysql安装目录下的support-files目录里,文件名为mysql-log-rotate
把mysql-log-rotate从/opt/mysql3306/support-files拷贝至/etc/logrotate.d目录下,修改其内容为:
[root@dbtest1 logrotate.d]# vi mysql-log-rotate
# The log file name and location can be set in
# /etc/my.cnf by setting the "log-error" option
# in either [mysqld] or [mysqld_safe] section as
# follows:
#
# [mysqld]
# log-error=/opt/mysql3306/data/mysqld.log
#
# In case the root user has a password, then you
# have to create a /root/.my.cnf configuration file
# with the following content:
#
# [mysqladmin]
# password =
# user=
#
# where "" is the password.
#
# ATTENTION: The /root/.my.cnf file should be readable
# _ONLY_ by root !
/opt/mysql3306/data/mysql-slow.log {
create 600 mysql mysql
dateext
notifempty
daily
rotate 5
missingok
# compress
postrotate
# just if mysqld is really running
if test -x /opt/mysql3306/bin/mysqladmin && \
/opt/mysql3306/bin/mysqladmin -uroot -p123456 ping &>/dev/null
then
/opt/mysql3306/bin/mysqladmin -uroot -p123456 flush-logs
fi
endscript
}
测试:
logrotate -f /etc/logrotate.d/mysql-log-rotate