MySQL client fails to connect to localhost on Windows, due to IPv6
A MySQL client running on Windows 2008 or Windows 7 may fail to connect to the host name of "localhost". This is due to windows resloving the host name of localhost to the IPv6 loopback address of ::1. Windows will resolve localhost to ::1, even if IPv6 is disabled on all local network adapters.
MySQL IPv6 status
MySQL Server version 5.5.3 (March 2010) and later support IPv6 connections to localhost, using the ::1 IPv6 address. So recent MySQL installations can at least listen for IPv6 client connections. But previous versions of MySQL server interpret ::1 as a string or host name, rather than an IP address.
解决办法:
①卸载ipv6 (这个办法有效但是不推荐)
②修改 hosts 文件,经过本人测试这个在win7上有效,win10修改后无效,ping localhost 还是返回的 ::1 而不是 127.0.0.1
③升级mysql。 既来之,则安之。mysql5.53以上版本支持ipv6 在my.ini 配置文件中添加 :
port=3306
bind-address=::