Retrieve Lost Password in MYSQL

Sometime, we forget the root password for mysql. It happened to me once in my company. The previous developer left and didn’t document where to look for passwords. Well, it is possible for the root user of the system to reset it anyway…

First shutdown mysql,

/etc/init.d/mysql stop

then

mysqld –skip-grant-tables –u root
mysql -u root
mysql> use mysql;
mysql> UPDATE user SET Password = PASSWORD(‘newpass’) WHERE User = ‘root’;
mysql> FLUSH PRIVILEGES;

If there is an error about certain ip cannot access the db, grant permission like so:

GRANT ALL ON *.* TO ‘someuser’@’somehost’;

make sure the host name is correct.

Author: bpeh

Bernard Peh is a great passioner of web technologies and one of the co-founder of Sitecritic.net Website Design and Reviews. He works with experienced web designers and developers everyday, developing and designing commercial websites. He specialises mainly in SEO and PHP programming.