After activating logrotate on my openSUSE LEAP 42.3 system with
# systemctl enable logrotate.service
# systemctl start logrotate.service
the journal displayed the error:
Mai 27 20:22:55 xenon logrotate[30522]: [61B blob data]
Mai 27 20:22:55 xenon logrotate[30522]: error: 'Access denied for user 'root'@'localhost' (using password: NO)'
Mai 27 20:22:55 xenon logrotate[30522]: /etc/logrotate.d/mysql failed, probably because
Mai 27 20:22:55 xenon logrotate[30522]: the root acount is protected by password.
Mai 27 20:22:55 xenon logrotate[30522]: See comments in /etc/logrotate.d/mysql on how to fix this
Mai 27 20:22:55 xenon logrotate[30522]: error: error running non-shared postrotate script for /var/log/mysql/mysqld.log of '/var/log/mysql/mysqld.log '
First problem:
The “See comments” line is wrong. The file /etc/logrotate.d/mysql does not exist. The correct file name is /etc/logrotate.d/mysql-community-server.
Second problem:
The fix proposed by the comments in /etc/logrotate.d/mysql-community-server does not work, or more precisely, it is not enough.
After creating the file /root/.my.cnf as proposed, the command “/usr/bin/mysqladmin ping” which logrotate wants to run in its postrotate script works fine when run as root.
However /etc/logrotate.d/mysql-community-server contains the directive “su mysql mysql” which causes the postrotate script to run as user mysql.
I fixed that by commenting out the “su mysql mysql” line but I wonder if that is the correct fix.