当安装了Mysql8.0以上版本,搭建SpringBoot环境时启动项目时会遇到以下错误:
(1)第一个坑
Caused by javax.net.ssl.SSLHandshakeException:java.security.cert.certificateException
解决办法
pom.xml中的mysql驱动包依赖修改为
mysql
mysql-connector-java
8.0.11
application.properties文件中的配置内容:
spring.datasource.driver-class-name=com.mysql.cj.jdbc.Driver
driverClassName: com.mysql.cj.jdbc.Driver
(2)第二个坑
java.sql.SQLException: The connection property 'zeroDateTimeBehavior' acceptable values are: 'CONVERT_TO_NULL', 'EXCEPTION' or 'ROUND'. The value 'convertToNull' is not acceptable.
java.lang.IllegalArgumentException: No enum constant com.mysql.cj.conf.PropertyDefinitions.ZeroDatetimeBehavior.CONVERTTONULL
解决办法:由于MySql废弃了convertToNull该写法,改为 CONVERT_TO_NULL
url=jdbc:mysql://xxx.xxx.xxx.xxx:3306/xxx?characterEncoding=utf8&useSSL=true&serverTimezone=UTC&zeroDateTimeBehavior=CONVERT_TO_NULL