So the other day I made an aptitude safe-upgrade and MySQL was upgraded. Thing is I made some changes and when I tried to restart MySQL I saw the following error.
user@server:~$ sudo /etc/init.d/mysql restart
[sudo] password for user:
Stopping MySQL database server: mysqld failed!
Starting MySQL database server: mysqld already running.
/usr/bin/mysqladmin: connect to server at ‘localhost’ failed
error: ‘Access denied for user ‘debian-sys-maint’@’localhost’ (using password: YES)’
user@server:~$
Well fixing this error is fixed changing the password for MySQL user debian-sys-maint. We will retrieve the password from the file /etc/mysql/debian.cnf.
server:~# cat /etc/mysql/debian.cnf
# Automatically generated for Debian scripts. DO NOT TOUCH!
[client]
host = localhost
user = debian-sys-maint
password = password
socket = /var/run/mysqld/mysqld.sock
[mysql_upgrade]
user = debian-sys-maint
password = password
socket = /var/run/mysqld/mysqld.sock
basedir = /usr
server:~#
We backup the MySQL databases.
user@server:~$ mysqldump -u root -p –all-databases > /tmp/backup.sql
Enter password:
user@server:~$
Now lets change the debian-sys-maint password in the database.
mysql>GRANT ALL PRIVILEGES ON *.* TO ‘debian-sys-maint’@’localhost’ IDENTIFIED BY ‘password’ WITH GRANT OPTION;
Now we should be able to safely restart the database server.
user@server:~$ sudo /etc/init.d/mysql restart
[sudo] password for user:
Stopping MySQL database server: mysqld.
Starting MySQL database server: mysqld.
Checking for corrupt, not cleanly closed and upgrade needing tables..
user@server:~$
References:
- Ubuntuforums