Got a problem with a mysql server installation on Debian. (Not my server so I have no idea what caused this...)

Installing new applications that add a database fail with error:

ERROR 1045 (28000): Access denied for user 'root'@'localhost' (using password: YES)

I can log in with the user, I've flushed permissions...

Then I can across this question: https://stackoverflow.com/questions/1709078/how-can-i-restore-the-mysql-root-users-full-privileges

But when I try to stop mysql, it fails with

error: 'Access denied for user 'debian-sys-maint'@'localhost' (using password: YES)'

2 Answers 2


Debian use debian-sys-maint account for management (start/stop etc.). Credentials are stored in /etc/mysql/debian.cnf - check if all are valid.

  • 1
    What to do if they are not ?
    – Loenix
    Apr 14, 2020 at 7:08
  • @Loenix what do you mean by "if they are not"?
    – Anders
    Oct 28, 2020 at 19:53
  • Wow it was a long time ago... If they are not in this file, I guess.
    – Loenix
    Oct 29, 2020 at 20:19
  • @Loenix Read my answer then, where I have a suggestion to reset those credentials.
    – Anders
    Jan 26, 2022 at 18:54

There are many ways of restoring the debian-sys-maint user. Most easy to do is to reconfigure package mysql-server-5.5. That if you know the password for the root user of MySQL, you can try to restore the user and its password in /etc/mysql/debian.cnf.

sudo dpkg-reconfigure mysql-server-5.5

To restore MySQL:s root password (or any MySQL-users password) you can use the debian-sys-maint account. You need to run mysql to get the password for the debian-sys-maint account.

sudo mysql --defaults-file=/etc/mysql/debian.cnf
mysql> UPDATE mysql.user SET Password=PASSWORD('secret') WHERE User='root';
mysql> QUIT;

So, never remove the user debian-sys-maint, as it is used in Debian to administrate MySQL (shut it down, roll logs, upgrade packages, check existans of root user in MySQL, set new root user password etc).

  • 2
    In my case i just sudo killall mysqld then run sudo dpkg-reconfigure mysql-server-5.5, Now everything is ok.
    – shgnInc
    Mar 6, 2015 at 19:26
  • 1
    sudo killall mysqld then run sudo dpkg-reconfigure mariadb-server-10.2 is what fixed it for me Mar 29, 2018 at 14:08
  • One should stop the service, not kill the daemon. And killing the server will get you unnecessary down time when the database is not accessible.
    – Anders
    Apr 11, 2018 at 16:55
  • @Anders If I have data in databases, Can I use this sudo dpkg-reconfigure mysql-server-5.5 command ? it will just reconfigure root or data will be lost? Actually I have root password but when I run service mysql status it gives error given in the question Oct 14, 2020 at 12:05
  • @NikhilRadadiya you should have backups of the data in your database, in all cases. :-) But it is a long time since I used mysql, I use mariadb and postgresql instead. Should work without reseting the data, just change the administration password. The root password is not used. Also, adjust for the package you have installed, it might not be 5.5 any longer.
    – Anders
    Oct 28, 2020 at 19:50

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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