Mybatis_Plus配置数据源遇到的坑

最近看了一下Mybatis_Plus官方文档,然后试着练习一下,测试的时候一直报错,最后找出原因,mysql版本的问题。
先贴一下报错内容

Sun Oct 14 00:45:30 CST 2018 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 8 的版本 所以数据源配置也得改一下 。

mysql 8 的数据源配置

spring.datasource.driver-class-name=com.mysql.cj.jdbc.Driver

spring.datasource.username=root//你的用户名.默认root

spring.datasource.password=123456//你的密码.默认root

spring.datasource.url=jdbc:mysql://127.0.0.1:3306/sell?useUnicode=true&characterEncoding=UTF8&useSSL=false&serverTimezone=UTC


mysql 5 的数据源配置

spring.datasource.driver-class-name=com.mysql.jdbc.Driver

spring.datasource.username=root//你的用户名.默认root

spring.datasource.password=123456//你的密码.默认root

spring.datasource.url=jdbc:mysql://127.0.0.1:3306/sell?useUnicode=true&characterEncoding=utf-8&useSSL=false


二者差异

因为高版本永远是兼容低版本的,所以Mysql5使用Mysql8的配置也是可以,但是相反则会报错。

Mysql 8 中spring.datasource.driver-class-name 的配置是

com.mysql.cj.jdbc.Driver

Mysql 5 的是

com.mysql.jdbc.Driver

Mysql8相比Mysql5 spring.datasource.ur 要多配置一个时区

serverTimezone=UTC

时区可以自己选择 UTC是本地时间

碰到如上问题的解决方案

1.如上更改数据源配置
2.修改mysql驱动版本



    mysql
    mysql-connector-java
    5.1.29



    mysql
    mysql-connector-java
    8.0.11

你可能感兴趣的:(数据源配置)