Try the command FLUSH PRIVILEGES
when you log into the MySQL terminal. If that doesn’t work, try the following set of commands while in the MySQL terminal
mysql -u root
mysql> USE mysql;
mysql> UPDATE user SET password=PASSWORD("NEWPASSWORD") WHERE User="root";
mysql> FLUSH PRIVILEGES;
mysql> quit
Change out NEWPASSWORD with whatever password you want. Should be all set!
Update: As of MySQL 5.7, the password
field has been renamed authentication_string
. When changing the password, use the following query to change the password. All other commands remain the same:
mysql> UPDATE user SET authentication_string=PASSWORD("NEWPASSWORD") WHERE User="root";
for MySQL 8.0+ Don’t use
mysql> UPDATE mysql.user SET authentication_string='password' WHERE User="root";
as it overwrites the authentication_string
, which is supposed to be a hash and not plain text, instead use:
mysql> `ALTER USER 'root'@'localhost' IDENTIFIED BY 'MyNewPass';`