I recently migrated one of our MySQL servers (Simply by using rsync) and afterwards when restarting the MySQL server I was faced with:
admin@db:~$ sudo /etc/init.d/mysql restart * Stopping MySQL database server mysqld <strong>[fail]</strong> * Starting MySQL database server mysqld [ OK ] /usr/bin/mysqladmin: connect to server at 'localhost' failed error: '<strong>Access denied for user 'debian-sys-maint'@'localhost'</strong> (using password: YES)'
This MySQL user is created for Ubuntu to be able to start/stop the database and to preform other maintenance operations.
The issue is that with each update to MySQL, the user’s password in the database is overwritten. Ubuntu searches the file /etc/mysql/debian.cnf in order to find this user’s password, but obviously the password was out of sync after copying the databases from the old database server.
First, check the contents of the /etc/mysql/debian.cnf file:
admin@db:~$sudo cat /etc/mysql/debian.cnf
The contents of the file should look something like the:
# Automatically generated for Debian scripts. DO NOT TOUCH! [client] host = localhost user = debian-sys-maint <strong>password = PASSWORD</strong> socket = /var/run/mysqld/mysqld.sock [mysql_upgrade] user = debian-sys-maint <strong>password = PASSWORD</strong> socket = /var/run/mysqld/mysqld.sock basedir = /usr
The PASSWORD is what we’re looking for.
Next, you will want to issue a command to MySQL to tell it to grant the debian-sys-maint user all necessary privileges using the new password.
Login to your MySQL server using your root account and the root password:
admin@db:~$ mysql -u root -p
Issue the GRANT command now to grant those permissions:
mysql> GRANT ALL PRIVILEGES ON *.* TO 'debian-sys-maint'@'localhost' IDENTIFIED BY 'PASSWORD';
Restart MySQL, you should no longer be getting the “access denied” error message.
admin@db:~$ sudo /etc/init.d/mysql restart * Stopping MySQL database server mysqld [ OK ] * Starting MySQL database server mysqld [ OK ] * Checking for corrupt, not cleanly closed and upgrade needing tables.
You may need to kill the MySQL server processes in order to get MySQL to shut down.

October 3rd, 2011
AfterDarkMike
Posted in
Tags:
Keep working ,splendid job!
I dont agree with this completely but it brings up some great points.
Thanks for posting this. Helped me out big time. Thanks!
Great post.
Good post, adding it to my own blog today, thanks.
Posted your page, MySQL: “Access denied for user ‘debian-sys-maint’@’localhost’” | Mike Johnson’s Personal Blog on digg. Regards, Kristie Zamacona
outstanding post!
Hello very nice web site!! Man ..
Thanks!
Thanks a lot for this article.
You’re welcome!
Awesome things here. I’m very satisfied to look at your article.