Java: SSL Connection to MySQL

eclipsejavajdbcMySQLssl

I am trying to connect to remote Mysql database through SSL connection using Java application in Eclipse.

I am using Virtualbox to host remote Mysql which has JDK. The SSL certificates are created in this guest machine (Linux). Trying to connect from host (Windows) which has it's own JDK. Eclipse installed in host.

When I run the java application it throws this message:

jdbc:mysql://x.x.x.x:3306/xxxdb? verifyServerCertificate=true&useSSL=true&requireSSL=true+user+password
Mon Nov 14 17:23:53 SGT 2016 WARN: Establishing SSL connection without server's identity verification is not recommended. According to MySQL 5.5.45+, 5.6.26+ and 5.7.6+ requirements SSL connection must be established by default if explicit option isn't set. For compliance with existing applications not using SSL the verifyServerCertificate property is set to 'false'. You need either to explicitly disable SSL by setting useSSL=false, or set useSSL=true and provide truststore for server certificate verification.

No: 1, tester1
No: 2, tester2
Closing database connection.
Closed!

From the message it says it says, (excerpt)

..or set useSSL=true and provide truststore for server certificate verification.

My confusion is, since I have JDK in both host and guest, where do I execute the
keytool command to import certificates into keystore for JVM to trust? Certificates are in guest machine, assumed remote.

Best Answer

You should run the command on the client (guest) machine once you imported the CA certificate.

If you would like to know more, please take a look at this link:

https://dev.mysql.com/doc/connector-j/5.1/en/connector-j-reference-using-ssl.html