Mysql – How to change the password for root@127.0.0.1 and root@example.com

MySQLpassword-protectedroot

I was looking at the users in my mysql.user table and noticed that there are 3 roots.

root@localhost
root@127.0.0.1
root@example.com

When I first discovered this none of the roots were password protected. I managed to password protect root@localhost but I can't figure out how to password protect the other two. How would I do this via the command line?

Thanks for any help.

Best Answer

SQL Query:

update user set password=PASSWORD("NEWPASSWORD") where User='root' AND Host="127.0.0.1";
update user set password=PASSWORD("NEWPASSWORD") where User='root' AND Host="example.com";