MySQL doesn't logs error to new file after rotating?

In the postrotate, I redirect both stderr and stdout to a log file to see what happens:

postrotate
    /usr/bin/mysqladmin flush-logs > /var/log/mysqladmin.flush-logs 2>&1
endscript

What I get is:

/usr/bin/mysqladmin: connect to server at 'localhost' failed
error: 'Access denied for user 'root'@'localhost' (using password: NO)'

It sounds like mysqladmin doesn't read /root/.my.cnf during logrotate.

So, try this:

postrotate
    env HOME=/root/ /usr/bin/mysqladmin flush-logs > /var/log/mysqladmin.flush-logs 2>&1
endscript

Source:

  • http://bugs.mysql.com/bug.php?id=51005
  • http://scribble.scran.ac.uk/svene/weblog/2893.html