Tuesday, January 31, 2012

Access denied for user 'root'@'localhost' (using password: NO)

Hi friends,

If you are getting error like this on MySQL database: "Access denied for user 'root'@'localhost' (using password: NO)" . And you forgot your Database password. Just follow the steps on your command prompt :

[Step-1]: /etc/init.d/mysqld stop
[Step-2]: mysqld_safe --skip-grant-tables &
[Step-3]: mysql -u root
[Step-4]: mysql> use mysql;
[Step-5]: mysql> update user set password=PASSWORD("newrootpassword") where User='root';
[Step-6]: mysql> flush privileges;
[Step-7]: mysql> quit
[Step-8]: /etc/init.d/mysqld stop
[Step-9]: /etc/init.d/mysqld start

Thanks,
Durgesh