If you’ve moved a MySQL installation from one Debian server to another and/or replaced the user logins on your system, you might get the error message "ERROR 1045 (28000): Access denied for user ‘debian-sys-maint’@’localhost’ (using password: YES)" when attempting to restart MySQL.
Debian based systems create a user in MySQL called "debian-sys-maint" with a random password. The file the password is stored in as at /etc/mysql/debian.cnf and will look something like this:
# Automatically generated for Debian scripts. DO NOT TOUCH! [client] host = localhost user = debian-sys-maint password = drlkgijhdrouiglr socket = /var/run/mysqld/mysqld.sock [mysql_upgrade] host = localhost user = debian-sys-maint password = drlkgijhdrouiglr socket = /var/run/mysqld/mysqld.sock basedir = /usr
The solution is to either reset the password for that MySQL user on the local host to what’s currently in the config file, or to copy the password from the config file on the original host to the one on this host.
Note that when copying the password over from the previous host, make sure it gets copied into both password fields in the config file – there are two with identical passwords.
Note also that the password in this file is not hashed in any way – it’s a plain text password.