Wednesday, September 28, 2011

Reset mysql 5.1 root pass

I had to install a couple of dbs on a mysql server which refused to recognize me as its root… I kept receiving the following not-so-friendly message:
ERROR 1045 (28000): Access denied for user 'root'@'localhost' (using password: YES)
As it turns out, something was messed up during the installation and mysql did not recognize the given root password (mistype perhaps?). Anyway, I had to reset the pass, and this is how I did it.


Stop the service:
sudo service mysql stop
Start on safe mode without permissions check:
sudo mysqld_safe --skip-grant-tables &
Login as root on mysql:
mysql -u root
Update the root user’s password in the corresponding table:
mysql> use mysql;
mysql> update user set password=PASSWORD("NEW-ROOT-PASSWORD") where User='root';
mysql> flush privileges;
mysql> quit
And then restart the mysql service...

No comments: