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