How can I login to MySQL as 127.0.0.1 or ::1 instead of localhost?

I’ve set different password for 'root'@'localhost' and 'root'@'127.0.01' like this:

mysql -u root
SET PASSWORD FOR 'root'@'localhost' = PASSWORD('pswd1');
SET PASSWORD FOR 'root'@'127.0.0.1' = PASSWORD('pswd2');

but when I try to login like this:

mysql -u root -p -h 127.0.0.1

I still have to use the first password pswd1 even though according to this:

enter image description here

another password pswd2 was set for 127.0.0.1.

What is the problem here? How can I set 3 different passwords for ‘root’@’localhost’, ‘root’@’127.0.0.1’ and ‘root’@’::1′ and login to those accounts with those passwords?

Go to Source
Author: JConstantine