2021-06-17 21:41:21 索煒達電子 4998
在JDBC連接Mysql數(shù)據(jù)庫的過程中出現(xiàn)了如下的警告信息:
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數(shù)據(jù)庫的SSL連接問題,提示警告不建議使用沒有帶服務(wù)器身份驗證的SSL連接,是在MYSQL5.5.45+, 5.6.26+ and 5.7.6+版本中才有的這個問題。解決辦法在警告中已經(jīng)說明了:
1.在數(shù)據(jù)庫連接的url中添加useSSL=false;
2.url中添加useSSL=true,并且提供服務(wù)器的驗證證書。如果只是做一個測試的話,沒必要搞證書那么麻煩啦,在連接后添加一個useSSL=false即可,例如:
jdbc:mysql://localhost:3306/test?useSSL=false
在使用Java進行JDBC連接的時候,可以在Properties對象中設(shè)置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) {
...
}
其實這個是不用寫出來的,但是一個同事懶啊,都不知道看警告信息,直接來問我,寫給懶的人看的,哈哈