I'm new to Linux and have setup a VPS running Ubuntu 16.04 with postfix, dovecot and rouncube using mariadb for the database. It all seem to be working okay but I regularly receive the following email:

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

I've done some searching and found a post suggesting I need to create a /root/.my.cnf file which I have done and have since restarted the server etc. but I am still receivng the error. The contents of my /root/.my.cnf are as follows:

password = *mypassword*
user = root

password = *mypassword*

Does anyone know if there is something I'm missing or anything else I need to configure to get this to use the mysql password perhaps?


  • You could try putting the user and password fields under the [client] section or [client-server]. – Synetech May 2 '18 at 7:22

This might be a bug in the 'stock' configuration when using mariadb as opposed to mysql that hasn't been stamped out yet, as I vaguely remember running into something similar myself when moving over to mariadb from mysql.

You will want to look in /etc/logrotate.d/mysql-server to see what is running at postrotate. You will likely have something like this:

test -x /usr/bin/mysqladmin || exit 0
if [ -f `my_print_defaults --mysqld | grep -oP "pid-file=\K[^$]+"` ]; then
    # If this fails, check debian.conf!
    mysqladmin --defaults-file=/etc/mysql/debian.cnf flush-logs

Ubuntu is probably looking there, so try taking a look in /etc/mysql/debian.cnf and seeing what is set.

| improve this answer | |
  • Hi, thanks for that. I'd seen another post somewhere that mentioned this file but someone had said not to put passwords in that file as it wasn't as secure or maybe it would get over written if there is an update perhaps, are you familiar with that? – Adam D Jan 27 '17 at 8:55
  • It shouldn't be less secure, really, as it should be owned by root with 600 permissions (read and write only for the owner). There is a small chance of it being overwritten in /etc but installation programs will prompt you before they do anything like that. – AvatarKava Jan 28 '17 at 17:55

AvatarKava gets us pointed in the right direction and his answer will work for most people. If you're still scratching your head after adding a user and password to the /etc/mysql/debian.cnf file (even though it says not to touch this file haha!) then:

make sure you have quotes around your password

especially if there are special characters in your password.

Another hack is to remove the --defaults-file=/etc/mysql/debian.cnf option from the mysqladmin command in /etc/logrotate.d/mysql-server. If you remove this option, the root user (the user that runs logrotate) will still need a valid user and password to connect to mysql so make sure you have a proper .my.cnf file in /root. In either case, the changes to debian.cnf or mysql-server could be overwritten during the next MariaDB upgrade but as AvatarKava points out, you will probably get prompted before the upgrade overwrites these files. Worst case, you'll start getting logrotate errors again after the upgrade and will need to make the same changes again.

| improve this answer | |
  • no need for quotes on my password, that contains ) – rubo77 Jul 10 at 1:41

In my case, recreate the debian-sys-maint user was the solution.

Here is how to do that :

  1. Use the SQL tab in your phpmyadmin or, on your linux console, log in mysql with :

    mysql -u root -p

enter your root password and continue

  1. run the following command:

    GRANT RELOAD, SHUTDOWN, PROCESS, SHOW DATABASES, SUPER, LOCK TABLES ON *.* TO 'debian-sys-maint'@'localhost' IDENTIFIED BY 'your-password'

you can find 'your-passowrd' in /etc/mysql/debian.cnf

# Automatically generated for Debian scripts. DO NOT TOUCH!
host     = localhost
user     = debian-sys-maint
password = your-password
socket   = /var/run/mysqld/mysqld.sock
host     = localhost
user     = debian-sys-maint
password = your-password
socket   = /var/run/mysqld/mysqld.sock

If you have the following message :

ERROR 1819 (HY000): Your password does not satisfy the current policy requirements

you will need to change your password or you can run the following commands to temporarily deactivate the password policy:

  1. uninstall plugin validate_password;

  2. GRANT RELOAD, SHUTDOWN, PROCESS, SHOW DATABASES, SUPER, LOCK TABLES ON *.* TO 'debian-sys-maint'@'localhost' IDENTIFIED BY 'your-password'

  3. INSTALL PLUGIN validate_password SONAME 'validate_password.so';

| improve this answer | |

Not the answer you're looking for? Browse other questions tagged or ask your own question.