mysqlログのローテート

mysqlのログはrpmでインストールした場合はOS標準のlogrotateでローテートされます。
ログの出力先を変更していたり、出力するログの種類を増やしている場合は定義を追加する。

またローテート時にはmysqladminコマンドが実行されるが、
rootパスワードを設定しているとエラーでローテートされないため、パスワード入力無く済むように変更する。

# vim /etc/logrotate.d/mysql

# 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=/var/lib/mysql/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 = <secret> 
# user= root
#
# where "<secret>" is the password. 
#
# ATTENTION: The /root/.my.cnf file should be readable
# _ONLY_ by root !

#/var/lib/mysql/mysqld.log {
/var/log/mysql/mysqld.log 
/var/log/mysql/mysqld-general.log 
/var/log/mysql/slow-query.log
{
        # create 600 mysql mysql
        notifempty
        daily
        rotate 5
        missingok
        compress
    postrotate
    # just if mysqld is really running
    if test -x /usr/bin/mysqladmin && \
       /usr/bin/mysqladmin --login-path=root ping &>/dev/null
    then
       /usr/bin/mysqladmin --login-path=root flush-logs
    fi
    endscript
}

results matching ""

    No results matching ""