mysql日志 logrotate_mysql的logrotate脚本

随着业务量的增加和时间的推移mysql的日志势必会越来越多、越来越大,那么就要用系统的logrotate轮替mysql的日志(logrotate可以参看:http://jim123.blog.51cto.com/4763600/1880582),当然平时用的mysql都是二进制包部署安装的,其实mysql的二进制包中的support-files文件夹里就有提供mysql的logrotate脚本,文件名为:mysql-log-rotate,当然如果要使用的话还是要修改下才能使用,如下是我修改过的mysql的logrotate脚本:# This logname can be set in /etc/my.cnf

# by setting the variable "err-log"

# in the [safe_mysqld] section as follows:

#

# [safe_mysqld]

# err-log=/usr/local/mysql/data/mysqld.log

#

# If the root user has a password you have to create a

# /root/.my.cnf configuration file with the following

# content:

#

# [mysqladmin]

# password = 

# user= root

#

# where "" is the password.

#

# ATTENTION: This /root/.my.cnf should be readable ONLY

# for root !

#这里日志文件为datadir下的*.log和*.err文件

/data/mysqldata/*.log /data/mysqldata/*.err {

create 600 mysql mysql

notifempty#如果日志为空logrotate不会进行

daily

rotate 3

missingok#日志logrotate期间任何错误都忽略

compress

postrotate#在logrotate之前要判断mysql是否启动,如果没有启动就flush-logs

# just if mysqld is really running

if test -x/usr/local/mysql/bin/mysqladmin && \

/usr/local/mysql/bin/mysqladmin ping &>/dev/null

then

/usr/local/mysql/bin/mysqladmin flush-logs

fi

endscript

}

[root@localhost support-files]# cp mysql-log-rotate /etc/logrotate.d/mysqld

把logrotate文件复制在logrotate.d文件夹里,这里主要一点是如果你的mysql的root用户有加密码,那么你要在root的家目录中新建.my.cnf添加以下内容,使得mysqladmin能用:[root@localhost ~]# vim .my.cnf

[mysqladmin]

user = root

host = 

password = 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值