您的位置:首页 > 数据库 > MySQL

使用localhost和127.0.0.1都无法连接mysql

2015-03-22 23:16 477 查看
如果这个时候使用用主机名和::1能够连接的话,那可以确定是被ipv6坑了

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

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

具体应看下面的说明:


Connecting To My Sql Server Using An Ipv6 Address

by Ashwani
Kumar - Oct 10th, 2012 - posted in Technical | Tagged
as ipv6, mysql | 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.
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: 
相关文章推荐