2011-10-14

How to reset MySQL root password

Just for the case you can't remember.

sudo /etc/init.d/mysql stop

# we have to --skip-networking to prevent connections out of localhost because mysql will now run absolutely unprotected
sudo /usr/sbin/mysqld --skip-grant-tables --skip-networking &
mysql -u root

# reload privileges from grant tables (free cached memory)
FLUSH PRIVILEGES;
USE mysql;

# set your new password
UPDATE user SET Password = PASSWORD('new password') WHERE Host = 'localhost' AND User = 'root';

# reload the privileges again
FLUSH PRIVILEGES;

# restart
sudo /etc/init.d/mysql stop
sudo /etc/init.d/mysql start

No comments:

Post a Comment