MySQL -h option invalid

At first, we should comfirm we create a user, like this


use mysql;
select Host,User from user;

I get this error in Centos+Mysql 5.6

For convenient, I created a user: example_user@%, but I still can not login with mysql -u example_user -h 127.0.0.1 -p, the error message said Access denied for user ‘example_user’@localhost , I specificated the host as 127.0.0.1, why converted to localhost? And the “%” character should match all host.

After a lot of test, 127.0.0.1 is same as localhost, and % not match localhost in this version of MySQL, so, we just have to create a user in localhost.


grant all on example_db.* on "example_user"@"localhost" identified by "your password";
flush privileges;

How to connect MySQL Server in wampserver

Open port will cause a security issue, so do that ONLY for dev or debug

I trust we all know that we should set an account for remote access in MySQL, such as


grant all on example_db.* on "example_user"@"%" identified by "your password";
flush privileges;

So, the reason is not misconfig of MySQL, it’s windows firewall, we have to open port by follow actions.

Search(win+Q)->Firewall-> Windows Defender Firewall-> inbound rule

create rule -> port -> release 3306 (sorry I don’t know what is it in English version)