1. 程式人生 > >Mysql:WARN: Establishing SSL connection without server's identity verification is not recommended.

Mysql:WARN: Establishing SSL connection without server's identity verification is not recommended.

在JDBC連線Mysql資料庫的過程中出現瞭如下的警告資訊:

 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.

是Mysql資料庫的SSL連線問題,提示警告不建議使用沒有帶伺服器身份驗證的SSL連線,是在MYSQL5.5.45+, 5.6.26+ and 5.7.6+版本中才有的這個問題。解決辦法在警告中已經說明了:

1.在資料庫連線的url中新增useSSL=false; 2.url中新增useSSL=true,並且提供伺服器的驗證證書。 如果只是做一個測試的話,沒必要搞證書那麼麻煩啦,在連線後新增一個useSSL=false即可,例如:

jdbc:mysql://localhost:3306/test?useSSL=false

在使用Java進行JDBC連線的時候,可以在Properties物件中設定useSSL的值為false,但是和寫在連結中是一樣的。比如

Properties properties = new Properties();
properties.setProperty("user", "root");
properties.setProperty("password", "milos23);
properties.setProperty("useSSL", "false");
properties.setProperty("autoReconnect", "true");
try (Connection conn = DriverManager.getConnection(connectionUrl, properties)) {
    ...
} catch (SQLException e) {
    ...
}