Thursday, September 18, 2008

MySQL Password change (Forgot root?)

"Anyone know the password to MySQL on sqlsrvr26?"

For whatever reason, maybe you are starting a job and have to clean up after the old admin left, you may need to reset the root password for MySQL. It doesn't get simpler than this:

/etc/init.d/mysqld stop
/usr/bin/mysqld_safe --skip-grant-tables &
mysql -h localhost
use mysql
update user set password = password('newpassword') where user = 'root' and host='localhost';
update user set password = password('newpassword') where user = 'root' and host='%';
quit
/etc/init.d/mysqld restart
The two update commands change root for localhost, and if you need to access it remotely like from PHPMyAdmin, the second update should take care of that. You probably only need the first update command though.

1 comments:

Anonymous said...

Thank you a lot :)