较新的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

笔者一个蒟蒻差点死在学习开发的路上。。。。

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