mysqladmin: connect to server at localhost failed

A common logrotate error if the mysql password is missing in /etc/mysql/debian.cnf

Anacron job ‚cron.daily‘ on Ubuntu

/etc/cron.daily/logrotate:
mysqladmin: connect to server at 'localhost' failed
error: 'Access denied for user 'root'@'localhost' (using password: NO)'
error: error running shared postrotate script for '/var/log/mysql/mysql.log /var/log/mysql/mysql-slow.log /var/log/mysql/mariadb-slow.log /var/log/mysql/error.log '
run-parts: /etc/cron.daily/logrotate exited with return code 1

Solution

vi /etc/mysql/debian.cnf
# Automatically generated for Debian scripts. DO NOT TOUCH!

[client]

host     = localhost user     = root password = Enter mysql-password here socket   = /var/run/mysqld/mysqld.sock

[mysql_upgrade]

host     = localhost user     = root password = Enter mysql-password here socket   = /var/run/mysqld/mysqld.sock basedir  = /usr