I've been having the same problem for a couple of weeks now. I have the following /etc/logrotate.d/mariadb
file configuration:
/var/log/mariadb/*.log {
create 600 mysql mysql
notifempty
weekly
rotate 12
missingok
delaycompress
postrotate
# just if mariadbd is really running
if test -x /usr/bin/mysqladmin && \
/usr/bin/mysqladmin ping &>/dev/null
then
env HOME=/root/ /usr/bin/mysqladmin --local flush-error-log \
flush-engine-log flush-general-log flush-slow-log
fi
endscript
}
I also made the /root/.my.cnf file with permission 400 and contents:
[mysqladmin]
password = <secret>
user= root
It rotates the log just to a new log file but when I check the new logs no errors are logged and I had to flush the logs manually every week. And if I run sudo logrotate /etc/logrotate.d/mariadb
the logs rotate just fine and new logs can be seen on the new log files. But if I let cron handle it weekly, the problem occurs.
Any idea on how to fix this issue? Thanks
env HOME
for the mysqladmin flush* commands you'd also need it on themysqladmin ping
. Your shell may have this already set. Maybe cron/logrotate doesn't. Its also possible that a global logrotate doesn't include the selinux permission to access /root/.my.cnf. Try putting credentials in non-globally readable/etc/my.cnf.d/mysqladmin.cnf
file..my.cnf
isn't read. This is honestly one reason that unix_socket auth permission on the root user are very useful, then its logs are rotatable and there's no password in a file that can leave access available. See also pr1556 (that I need to review again).ls -l
before and after the rotate script runs.-rw-------. 1 mysql mysql 619980 Oct 20 08:23 mariadb-err.log -rw-------. 1 mysql mysql 3357147 Oct 19 07:12 mariadb-err.log-20211017
After runningsudo logrotate /etc/logrotate.d/mariadb
I get-rw-------. 1 mysql mysql 79 Oct 20 08:24 mariadb-err.log -rw-------. 1 mysql mysql 619980 Oct 20 08:23 mariadb-err.log.1 -rw-------. 1 mysql mysql 3357147 Oct 19 07:12 mariadb-err.log-20211017