較新的mysql 由於driver和url引發的異常

這裏是ecilpse的錯誤提示Tue Sep 19 23:08:26 CST 2017 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.

千萬千萬要看錯誤提示啊。。。。花了好久,才發現這裏有說

按裏面說的ssl的使用要在url裏面設置,另外的博客說時區也用,就都加進去吧

舊的版本url=jdbc:mysql://127.0.0.1:3306/test?useUnicode=true&characterEncoding=utf8

其中test是我的數據庫

新版本url=jdbc:mysql:///test?serverTimezone=UTC&characterEncoding=utf8&useUnicode=true&useSSL=false

或者or set useSSL=true and provide truststore for server certificate verification.

這裏貼出mysql的url的配置

jdbc:mysql://127.0.0.1:3306/******characterEncoding=utf8&useSSL=false&serverTimezone=UTC&allowPublicKeyRetrieval=true
解析:
    characterEncoding=utf8  (字符編碼)
    useSSL=false    (發現是8版本開始才需要添加,5.X印象中不需要,添加這個參數可能和MySQL的SSL連接設置有關係)
    serverTimezone=UTC  (當連接數據庫時候,出現Time Zone錯誤時添加此參數)

    allowPublicKeyRetrieval=true    (使用root賬戶登陸沒問題,使用普通賬戶會提示Public Key Retrieval錯誤)

然後drive也有的地方需要是,新的com.mysql.cj.jdbc.Driver而不是舊版本的com.mysql.jdbc.Driver

筆者一個蒟蒻差點死在學習開發的路上。。。。

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