Thursday, 30 August 2007

MySQL Password Reset Root


If you're reading this - chances are, you're an idiot. I know this as I am also an idiot as I installed a development server recently and forgot the root password for mysql. Yes I should have written the password down, no I didn't. here's the steps for resetting the root password on a working linux server;

1.) First login as root via ssh
2.) kill the mysqld service and all other mysql running processes e.g.
#> service mysqld stop
#> ps waux

ps waux gets a list of all running processes

use kill to stop any running mysql processes eg kill 6194 (kill pid).

3.) After stopping/killing mysqld, run the foillowing line;
#> mysqld_safe --skip-grant-tables &

4.) You are now logged into mysql safe mode. Cut and paste the following lines

mysql -u root mysql
UPDATE user SET password=PASSWORD("your_password") WHERE User="root";

5.) then start up the mysqld service;

#> service mysqld start

That's it - all done. Now remember to write down ur password this time u idiot!


Anonymous said...

invaluable - with just a few mods for our system:-

killall mysqld

mysql -u root mysql

mysql > UPDATE user SET password='newpass' WHERE User='root';

mysql > mysql FLUSH RIVILEGES;

mysql > exit;


Anonymous said...

typo line 4:-

mysql > mysql FLUSH PRIVILEGES;