Friday, January 1, 2010

How to reset/change MySQL root password

I think I should need to post this one so that I can remember if ever I will encounter it again. I tried to study Drupal again for some reason and suddenly when I try to check the database I forgot to note down its root password. Now here comes my Google friend and it helps me out found answers to solved my problem.

Here are the four steps to undertake the process: (By the way, I test this on Jaunty and I could not guarantee if it works also on other Linux distro. But I am 90% sure that it will.)

1. We need to stop mysql from running.

sudo /etc/init.d/mysql stop

2. And then start the mysql configuration.

sudo mysqld --skip-grant-tables &

Before I forgot, on this command the process will not close. So you need to supply the third command.

3. Login to MySQL as root.

mysql -u root mysql

Then this command will login you to mysql command prompt.

4. Replace YOURNEWPASSWORD with your new password.

UPDATE user SET Password=PASSWORD('YOURNEWPASSWORD') WHERE User='root'; FLUSH PRIVILEGES; exit;

And please be reminded also that this method is not regarded as the safest way of resetting the password. However it works for me.

My reference on this one. Click here.

No comments:

Post a Comment