天天看點

MySQL: Error 1045 (28000): Access denied for user ‘root’@'localhost’ (using password: NO)

原位址:http://myotragusbalearicus.wordpress.com/2011/11/21/mysql-error-1045-28000-access-denied-for-user-rootlocalhost-using-password-no/

I’ve upgraded MySQL server version to 5.1.54-1ubuntu4 and when I try to connect to the database I’m getting this error:

$ mysql -u root
 
Error 1045 (28000): Access deniedfor user 'root'@'localhost'(using password: NO)
           

Maybe updating the package the updater overwrote the root password.

To restore it:

  • Stop mysqld deamons.
$sudo service mysql stop
           
  • Go  to  mysql/bin directory
$cd /usr/bin
           
  • Start a mysql deamon with this option:
$sudo mysqld_safe --skip-grant-tables
           
  • Open another terminal and open a mysql session to execute this:
$ mysql
mysql> use mysql;
mysql> UPDATE user SET password=PASSWORD('YOUR_NEW_PASSWORD_HERE') WHERE user ='root';
mysql> exit;
           
  • Now kill the mysqld_safe process and restart mysqld normally:
$sudo service mysql start