使用localhost和127.0.0.1都无法连接mysql

如果这个时候使用用主机名和::1能够连接的话,那可以确定是被ipv6坑了

因为IPv6协议将localhost和127.0.0.1都映射为::1

这个时候需要按照ipv6的地址进行连接

具体应看下面的说明:

Connecting To My Sql Server Using An Ipv6 Address

 - Oct 10th, 2012 - posted in Technical | Tagged as ipv6mysql Comments

If you are one of those who does not know that there is a new way to connect to MySQL database with an IPV6 IP address, then keep reading. We will see how to connect to a mysql database on a server with an IPv6 address.

I struggled for this, so I wanted to document it. Source: Wiki IPv6

Address Format

IPv6 addresses have two logical parts: a 64-bit network prefix, and a 64-bit host address part.

(The host address is often automatically generated from the interface MAC address.) An IPv6 address is represented by 8 groups of 16-bit hexadecimal values separated by colons (:) shown as follows:

A typical example of an IPv6 address is:

2001:0db8:85a3:0000:0000:8a2e:0370:7334.

The hexadecimal digits are case-insensitive.

Method to connect to MYSQL using an IPv4 address (traditional way)
1
2
3
4
urlString = “jdbc:mysql://10.144.1.216:3306/dbName”;
Class.forName(driver);
DriverManager.setLoginTimeout(getConnectionTimeOut());
dbConnection = DriverManager.getConnection(urlString,user,password);
Method to connect to MYSQL using an IPv6 address (New way)
1
2
3
4
urlString = “jdbc:mysql://address=(protocol=tcp)(host=fe80::5ed6:baff:fe14:a23e)(port=3306)/db”;
Class.forName(driver);
DriverManager.setLoginTimeout(getConnectionTimeOut());
dbConnection = DriverManager.getConnection(urlString,user,password);

This new approach is no where documented over the internet, and a bug has been filed by Mark Mathews to include this as documentation in next release of MYSQL JDBC connector. Thanks to Mark for Pointing this out to us.


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值