如何使用 SSL JDBC 连接到 MySQL 服务器
How to connect to MySQL server using SSL JDBC
您好,我正在尝试使用 java 远程登录我的 MySQL 数据库。我创建了一个需要 SSL 的远程帐户。我按照本指南做到了这一点:https://www.digitalocean.com/community/tutorials/how-to-configure-ssl-tls-for-mysql-on-ubuntu-16-04。
现在,一旦我尝试连接到数据库 Java 就会抛出此错误:
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.
所以我把这个添加到我的 URL:
+ "&useSSL=true"
+ "&requireSSL=true";
但现在它需要我给它一个trustStore
和一个trustStorePassword
。我在哪里或如何 find/create 这些?
我的 MySQL 服务器是 运行 在 VPS ubuntu 服务器上 btw。
您可以使用 keytool 命令创建和导入服务器的证书:
keytool -import -alias mysql -file server-cert.pem -keystore mycerts -storepass changeit
其中 server-cert.pem 是 mysql 的证书(您可以按照此 link 下的说明获取:http://do.co/2FaIK8F,mycerts 将是您的证书trustStore(命令会创建),trustStorePassword为changeit(当然选一个)
server-cert.pem就是你教程中提到的那个文件,里面有服务器的证书。
然后您需要使用以下代码将 trustStore
添加到您的 Java:
System.setProperty("javax.net.ssl.trustStore", "mycerts");
System.setProperty("javax.net.ssl.trustStorePassword", "changeit");
其中 changeit 是您在 keytool 命令中选择的密码,其中 mycerts 是 trustStore 的路径。
您好,我正在尝试使用 java 远程登录我的 MySQL 数据库。我创建了一个需要 SSL 的远程帐户。我按照本指南做到了这一点:https://www.digitalocean.com/community/tutorials/how-to-configure-ssl-tls-for-mysql-on-ubuntu-16-04。
现在,一旦我尝试连接到数据库 Java 就会抛出此错误:
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.
所以我把这个添加到我的 URL:
+ "&useSSL=true"
+ "&requireSSL=true";
但现在它需要我给它一个trustStore
和一个trustStorePassword
。我在哪里或如何 find/create 这些?
我的 MySQL 服务器是 运行 在 VPS ubuntu 服务器上 btw。
您可以使用 keytool 命令创建和导入服务器的证书:
keytool -import -alias mysql -file server-cert.pem -keystore mycerts -storepass changeit
其中 server-cert.pem 是 mysql 的证书(您可以按照此 link 下的说明获取:http://do.co/2FaIK8F,mycerts 将是您的证书trustStore(命令会创建),trustStorePassword为changeit(当然选一个)
server-cert.pem就是你教程中提到的那个文件,里面有服务器的证书。
然后您需要使用以下代码将 trustStore
添加到您的 Java:
System.setProperty("javax.net.ssl.trustStore", "mycerts");
System.setProperty("javax.net.ssl.trustStorePassword", "changeit");
其中 changeit 是您在 keytool 命令中选择的密码,其中 mycerts 是 trustStore 的路径。