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

轉自:https://blog.csdn.net/u010429286/article/details/77750177

 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) {
        ...
    }

其實這個是不用寫出來的,但是一個同事懶啊,都不知道看警告信息,直接來問我,寫給懶的人看的,哈哈

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章