MySQL working with 127.0.0.1 but not working with

2020-02-10 15:32发布

I have a strange problem in php MySQL:

php connects with 127.0.0.1 but not with localhost.

How to solve this issue?

9条回答
Bombasti
2楼-- · 2020-02-10 16:33

Try ping localhost in a command line, it may be resolving to ::1: the IP6 equivalent to 127.0.0.1

To fix it, add (or uncomment) the line:

   127.0.0.1       localhost

in C:\WINDOWS\system32\drivers\etc\hosts

查看更多
闹够了就滚
3楼-- · 2020-02-10 16:33

Is localhost resolving to the IPv6 address, as opposed to the IPv4, and MySQL is not listening on the v4 address?

The solution is make localhost resolve to the v4 address, OR make MySQL listen on the v6 address.

查看更多
成全新的幸福
4楼-- · 2020-02-10 16:36

I remember that being a longstanding and documented feature of Mysql on Windows. Something about the way local sockets work or something.

查看更多
登录 后发表回答