Page 1 of 1

Logrotate for myslqd.log

Posted: Thu Jan 17, 2019 7:22 am
by Deantwo
Investigating disk space issues on our Nagios VM revealed a myslqd.log file with the size of 25GB. The log file has been growing since the server was setup in 2016.

Is there anyway to enable logrotation for the myslqd.log file? So it is saved in a new file every month or week, and files of x age be deleted.
If it isn't already possible, can I make this as a feature request?

Re: Logrotate for myslqd.log

Posted: Thu Jan 17, 2019 4:06 pm
by lmiltchev
You should already have a logrotate script in the "/etc/logrotate.d/" directory, named "mysqld". Open it in a text editor, and comment out the section on the bottom:

Code: Select all

/var/log/mysqld.log {
        create 640 mysql mysql
        notifempty
        daily
        rotate 3
        missingok
        compress
    postrotate
        # just if mysqld is really running
        if test -x /usr/bin/mysqladmin && \
           /usr/bin/mysqladmin ping &>/dev/null
        then
           /usr/bin/mysqladmin flush-logs
        fi
    endscript
}
Change any options that you need to, e.g. "daily" to "weekly", etc.

In the "/etc/my.cnf" file, you would need to add a username/password, e.g:

Code: Select all

[mysqladmin]
password = nagiosxi
user= root
You can test the log rotation by running:

Code: Select all

logrotate -f /etc/logrotate.d/mysqld

Re: Logrotate for myslqd.log

Posted: Fri Jan 18, 2019 6:05 am
by Deantwo
Ok, I have set it up like you suggested.
Thanks.

Just confused as to why this isn't standard on the NagiosXI VM.

Re: Logrotate for myslqd.log

Posted: Fri Jan 18, 2019 10:01 am
by lmiltchev
Ok, I have set it up like you suggested.
Thanks.
I am glad I could help!
Just confused as to why this isn't standard on the NagiosXI VM.
It's a good question - I will discuss it with our developers.

I will be closing this topic now. If you have any further issues/questions, please start a new thread.