mysql-connector-java 版本8以上使用注意

做一个新产品调试,测试库数据库突然被产品部的小弟弟给干掉了,加班,他们都没来,就自己本地搭一个服务器进行测试。 没想到一下出了好多问题。

下载了8.1.12的mysql 数据库,然后就使用了对应版本的mysql jar包,却发现发现连不上数据库。

第一次运行报错 同时还警告数据库驱动字符串有问题,需要用 “com.mysql.cj.jdbc.Driver”,比以前多一个cj,

于是就更改了驱动字符串再次运行,

第二

Sat Mar 23 16:43:53 CST 2019 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.
java.sql.SQLNonTransientConnectionException: Could not create connection to database server. Attempted reconnect 3 times. Giving up.

然后下面一串创建连接失败,这个就比较简单了字面意思,ssl证书验证问题, 按照提示在连接字符串后面添加 useSSL=false,禁用掉这个验证。

再次运行:

java.sql.SQLNonTransientConnectionException: Could not create connection to database server. Attempted reconnect 3 times. Giving up.

 The server time zone value 'Öйú±ê׼ʱ¼ä' is unrecognized or represents more than one time zone. You must configure either the server or JDBC driver (via the serverTimezone configuration property) to use a more specifc time zone value if you want to utilize time zone support

再次报错,时区问题,这个问题不知道怎么处理,就去百度了下如何设置时区,在连接字符串后拼接 serverTimezone=GMT 

再次运行,运行成功。  

好了分享到次,下次见

猜你喜欢

转载自blog.csdn.net/hei164730739/article/details/88763688