没有所谓的捷径
一切都是时间最平凡的累积

windows2016 mysql连接慢,localhost被解析为ipv6的解决办法

站长整理辛苦,觉得有用评论点个赞吧,若转载请注明出处。如果文章内容失效,请反馈给本站,谢谢!

今天遇到个奇怪的问题,mysql用localhost连接很慢,影响查询效率,服务器是windows2016,改用127.0.0.1就正常。网上查找资料,找到了一篇英文文章(原贴地址:http://superuser.com/questions/436574/ipv4-vs-ipv6-priority-in-windows-7/436944#436944)。大概意思是ipv6优先级高,localhost默认走ipv6地址。所以mysql用localhost时windows把localhost 解析为 ipv6 地址 ::1 而不是 127.0.0.1,发现连不上失败再走ipv4,这样就影响了数据库查询效率,豫章小站目前的解决办法是修改用127.0.0.1连接mysql。另外还有一个解决方案,修改my.ini,添加bind-address = :: 监听ipv6,还可以按下面说的修改注册表。

SOLUTION #1: ADD A PREFIX POLICY TO PREFER IPV4 ADDRESSES OVER IPV6
Prefix policy table is similar a routing table, it determines which IP addresses are preferred when making a connection. Note that higher precedence in prefix policies is represented by a lager "precedence" value, exactly opposite to routing table "cost" value.

Default Windows prefix policy table:

C:\>netsh interface ipv6 show prefixpolicies
Querying active state...

Precedence Label Prefix
---------- ----- --------------------------------
50 0 ::1/128
40 1 ::/0
30 2 2002::/16
20 3 ::/96
10 4 ::ffff:0:0/96
5 5 2001::/32
Note that IPv6 addresses (::/0) are preferred over IPv4 addresses (::/96, ::ffff:0:0/96).

We can create a policy that will make Hurricane Electric IPv6 tunnel less favourable than any IPv4 address:

netsh interface ipv6 add prefixpolicy 2001:470::/32 3 6
2001:470::/32 is Hurricane Electric's prefix, 3 is a Precedence (very low) and 6 is a Label.

I could have used a more generic prefix, but I wanted to make sure than if and when I get a direct IPv6 connectivity from an ISP, it will take precedence over IPv4.

If you adapt this solution, you need to substitute an appropriate IPv6 prefix instead of my Hurricane Electric one.

SOLUTION #2: TWEAK REGISTRY TO MAKE WINDOWS ALWAYS PREFER IPV4 OVER IPV6
This solution is more generic, but more invasive and less standards-compliant. In the end, Windows will still modify the prefix policy table for you.

Open RegEdit, navigate to HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\tcpip6\Parameters
Create DisabledComponents DWORD registry value, set its value to 20 (Hexadecimal). SeeMicrosoft KB 929852 for more info about this registry key, especially if DisabledComponentsalready exists on your system.
Reboot.

解决办法:

这篇文章解决办法是修改注册表。在命令行里面输入regedit打开注册表,找到键 HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\tcpip6\Parameters ,添加类型为DWORD 名字为 DisabledComponents 的项(已经有了的不用添加直接改值)。然后修改值为 20,值类型为16进制 。修改之后保存重启电脑。

» 本文链接地址:https://blog.mydns.vip/2131.html
» 如果喜欢可以: 点此订阅本站
赞(2) 打赏
声明:本站发布的内容(图片、视频和文字)以原创、转载和分享网络内容为主,若涉及侵权请及时告知,将会在第一时间删除,联系邮箱:contact@mydns.vip。文章观点不代表本站立场。本站原创内容未经允许不得转载,或转载时需注明出处:豫章小站 » windows2016 mysql连接慢,localhost被解析为ipv6的解决办法
分享到: 更多 (0)

评论 抢沙发

  • 昵称 (必填)
  • 邮箱 (必填)
  • 网址

智慧源于勤奋,伟大出自平凡

没有所谓的捷径,一切都是时间最平凡的累积,今天所做的努力都是在为明天积蓄力量

联系我们赞助我们

觉得文章有用就打赏一下文章作者

支付宝扫一扫打赏

微信扫一扫打赏