Bug #51005 mysqladmin does not read /root/.my.cnf for password on RHEL5 during logrotate
Submitted: 8 Feb 2010 19:16 Modified: 18 Feb 2010 13:17
Reporter: Chris Stankaitis Email Updates:
Status: Not a Bug Impact on me:
None 
Category:MySQL Server: Command-line Clients Severity:S3 (Non-critical)
Version:5.1.42 OS:Linux (RHEL5.4)
Assigned to: CPU Architecture:Any

[8 Feb 2010 19:16] Chris Stankaitis
Description:
/usr/bin/mysqladmin flush-logs will read the /root/.my.cnf for the root password if I run it on command line, but will not do so when run out of logrotate.d

Contents of /root/.my.cnf (owner: root:root perms: 600)

[mysqladmin]
password = STRIPPED
user = root

[mysql]
password = STRIPPED

logrotate:

/var/lib/mysql/mysqld.log {
        # create 600 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
}

How to repeat:
install MySQL 5.1.42 community
setup /root/.my.cnf
setup logging in /etc/my.cnf

should see a daily error from logrotate complaining about the postrotate part.
[9 Feb 2010 6:41] Sveta Smirnova
Thank you for the report.

> should see a daily error from logrotate complaining about the postrotate part.

Please send us this error you get.
[9 Feb 2010 14:21] Chris Stankaitis
As requested this is the email we are getting daily from logrotate via Cron

/etc/cron.daily/logrotate:

/usr/bin/mysqladmin: connect to server at 'localhost' failed
error: 'Access denied for user 'root'@'localhost' (using password: NO)'
error: error running postrotate script for /var/lib/mysql/mysqld.log
[9 Feb 2010 16:31] Sveta Smirnova
Thank you for the feedback.

> error: 'Access denied for user 'root'@'localhost' (using password: NO)'

You should either adjust your OS settings for daemon or add option --defaults-file to command which invokes mysqladmin.

So this is not MySQL bug.
[9 Feb 2010 22:02] Chris Stankaitis
I would like some clarification, we are following the documentation which was provided by MySQL for this and it never mentioned either of your proposed solutions.  

We want to make sure that whatever we do alters the base OS as little as possible.  We don't want to get into a position where upgrading MySQL will mean having to redo this process because of some custom thing we have to do to get this working.
[18 Feb 2010 13:17] Chris Stankaitis
Could I please get an update on this based on my above comment?
[21 Nov 2011 7:14] Trent Lloyd
The reason this does not work is because $HOME is not set in a cron environment.

The MySQL problem here is it would be desirable to have /root/.my.cnf read as it would generally be NOT desirable to store the MySQL root password in /etc/mysql/my.cnf which is read - as that is available to the system.

Since the stock shipped logrotate scripts in RPM does not allow any password configuration without customizing the script, it would be ideal to ship a configuration that allowed storing the MySQL password in a non globally readable location.
[24 Nov 2017 23:16] Artem Russakovskii
Hmm, it's 2017, and it's still somehow a problem. Started happening after updating OpenSUSE from 42.1 to 42.3.
[24 Nov 2017 23:38] Artem Russakovskii
The solution I went with is appending --defaults-extra-file=/root/.my.cnf to mysqladmin calls in /etc/logrotate.d/mysql-community-server. Now logrotate is working correctly.