Connecting to MySQL (on Google Cloud SQL) via JDBC and IPv6?

I would like to connect to Google Cloud SQL from an external application using JDBC and an instance IPv6 address as shown in my google developer console (confusing here):

String url      = "jdbc:mysql://abcd:abcd:abcd:abcd:abcd:abcd:abcd:abcd";
String user     = "root";
String password = "<also_obfuscated>";

connection = DriverManager.getConnection(url, user, password);

      

This results in the following exception:

com.mysql.jdbc.exceptions.jdbc4.MySQLNonTransientConnectionException: 
Cannot load connection class because of underlying exception: 
'java.lang.NumberFormatException: 
For input string: "abcd:abcd:abcd:abcd:abcd:abcd:abcd:abcd"'.

      

I am using the latest MySQL JDBC driver. Connecting via JDBC and IPv4 works but requires an additional configuration step and incurs a (small) additional cost.

So it is even possible to connect to MySQL via JDBC and IPv6, and if so, how?

UPDATE According to the documentation, this url should work for IPv6:

jdbc:mysql://address=(protocol=tcp)(host=abcd:abcd:abcd:abcd:abcd:abcd:abcd:abcd)(port=3306)

      

However, I am now getting the following exception:

com.mysql.jdbc.exceptions.jdbc4.CommunicationsException: 
Communications link failure
The last packet sent successfully to the server was 0 milliseconds ago. 
The driver has not received any packets from the server.

      

Apart from the JDBC driver that supports IPv6 (which it does, according to the documentation), and the client OS that supports IPv6 (which should work like OS X Yosemite), and the server OS that supports IPv6 (which Google Cloud does because it tells IPv6 server), what other parts need to be installed to work with IPv6 client-server connections?

eg. Should my provider provide any specific support?

+3


source to share


3 answers


You need to register the IPV6 address from which you will access the Google Cloud SQL Server among the allowed addresses on the Cloud SQL Console.

You can check this IPv6 address, for example, by visiting sites like whatismyv6.com.



Then all your ISP has to do is provide a stable IPV6 address (alas, even to this day, not all - alas AT&T Uverse, my ISP at home, for example, is not working).

Even in places where I could reliably get a stable IPv6 address, I had exactly the same problem, initially - until it became known to me that if I come with an IPv6 address and what I authorized, IPv4 one, Google Cloud SQL cannot "translate" one to the other to find out that I am truly authorized! -)

+3


source


Please note that if you do not have and cannot obtain an IPv6 address from which to connect (for example, connecting from a home computer through an ISP that does not yet support IPv6), you can click "Request IPv4 address" in the Google Developers Console / Storage / Cloud SQL / [Your Intance] / Access Control / IP and you will get one of them (within seconds) that will cost $ 0.01 per hour, paid off your 300 free credit US dollars if you still have this loan. Once you move your application to, for example, one of Google's application servers, you can surely get an IPv6 address. Free up the IPv4 address while saving credit.



0


source


Try

String url = "jdbc:mysql://[abcd:abcd:abcd:abcd:abcd:abcd:abcd:abcd]";

      

In URLs, literal IPv6 addresses must be surrounded []

so that the parser can tell the difference between the portions of the address and the optional port number, which is also split :

.

It is often easier to use hostnames instead of literal IP addresses. It remains independent of the IP protocol used, and it is also easier to change addresses.

-1


source







All Articles