Tuesday, January 11, 2011

Stopping MySQL database server : mysqld failed!

Today, after copying the content of /var/lib/mysql (which is where my database is stored) from one virtual machine to another, I was unable to restart mysqld. The error was:
  1. dbserver1:/var/log# /etc/init.d/mysql restart  
  2. Stopping MySQL database server: mysqld failed!  
  3. Starting MySQL database server: mysqld already running.  
  4. /usr/bin/mysqladmin: connect to server at 'localhost' failed  
  5. error: 'Access denied for user 'debian-sys-maint'@'localhost' (using password: YES)'  
  6. dbserver1:/var/log#  
I was quite surprised then I realized that the "access denied" error was pointing me to a problem with the password of the special MySQL user "debian-sys-maint". After a few investigations I finally got the root cause of the problem: during the installation MySQL generates a random password for "debian-sys-maint" and stores its credentials inside /etc/mysql/debian.cnf as well as inside the "users" table in the database itself. When I copied the database form one VM to another the two passwords (the one on the local debian.cnf and the one in the original database) were not matching anymore.

So, for the solution, find your "debian-sys-maint" password in /etc/mysql/debian.cnf:
  1. cat /etc/mysql/debian.cnf  | grep password
Then connect to MySQL with root:
  1. mysql -u root -p<your_root_password>
Use now the following SQL command to recreate the user (but replace <password> with your debian-sys-maint password!):
  1. GRANT ALL PRIVILEGES ON *.* TO 'debian-sys-maint'@'localhost' IDENTIFIED BY '<password>' WITH GRANT OPTION;  
Now the passwords in MySQL db and in debian.cnf are matching and MySQL should start correctly.

For more information about MySQL I heartedly suggest to check Planet MySQL @ http://planet.mysql.com/

Hope this helps!


  1. Thanks a lot!!! My SQL-server WORKS now!!!

  2. Thank you, just what I needed. I knew I had to adjust that password!

  3. thanks, that worked!

  4. Wow, was this ever helpful...

  5. thanks!. This worked for me on Debian Squeeze 6.0.3. No I no longer stare in misery at the red warning during boot up...

  6. Fantastic, saved my bacon. Thanks so much - bookmarking this blog!

  7. works perfect! thx


Related Posts Plugin for WordPress, Blogger...