设为首页 加入收藏

TOP

MySQL的logrotate脚本
2017-03-01 08:15:26 】 浏览:361
Tags: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 =


】【打印繁体】【投稿】【收藏】 【推荐】【举报】【评论】 【关闭】 【返回顶部
上一篇MySQL Online DDL 黄金准则 下一篇Oracle服务器自动备份

最新文章

热门文章

Hot 文章

Python

C 语言

C++基础

大数据基础

linux编程基础

C/C++面试题目