MySQL root password change

I have been trying to reset my MySQL root password. I have run mysqld_safe --skip-grant-tables, updated the root password, and checked the user table to make sure it is there.

Once restarting the MySQL daemon I tried logging in with the new root password that I just set and still get Access denied for user 'root' errors. I have also tried completely removing and reinstalling MySQL (including removing the my.cnf file) and still no luck. What can I do next?


SET PASSWORD FOR 'root'@'localhost' = PASSWORD('mypass');
FLUSH PRIVILEGES;

Have a look at this from the MySQL reference manual:

First log in to MySQL:

mysql -u root -p

Then at the mysql prompt, run:

UPDATE mysql.user SET Password=PASSWORD('MyNewPass') WHERE User='root';

Then

FLUSH PRIVILEGES;

Look at this page for more information: Resetting the Root Password: Unix Systems

UPDATE:

For some versions of mysql, the password column is no longer available and you'll get this error:

ERROR 1054 (42S22): Unknown column 'Password' in 'field list'

In this case, use ALTER USER as shown in the answer below.