ITPub博客

首页 > 数据库 > MySQL > mysql慢查询日志分割

mysql慢查询日志分割

原创 MySQL 作者:wzgchen 时间:2015-12-08 09:57:48 0 删除 编辑
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 

来自 “ ITPUB博客 ” ,链接:http://blog.itpub.net/91975/viewspace-1867980/,如需转载,请注明出处,否则将追究法律责任。

请登录后发表评论 登录
全部评论

注册时间:2015-05-01

  • 博文量
    383
  • 访问量
    181179