一、springboot配置文件中配置mysql驱动类时
spring.datasource.url=jdbc:mysql://localhost:3306/springboot?useUnicode=true&characterEncoding=UTF-8
spring.datasource.username=root
spring.datasource.password=sx96411
spring.datasource.driver-class-name=com.mysql.cj.jdbc.Driver
com.mysql.jdbc.Driver是mysql-connector-java 5中的驱动类路径
mysql-connector-java 6中修改为com.mysql.cj.jdbc.Driver
spring.datasource.driver-class-name属性也可以不用配置,springboot会检测数据库类型并自动配置相关的驱动类。
当配置spring.datasource.driver-class-name=com.mysql.jdbc.Driver时,spring boot会给出警告信息:
Loading class `com.mysql.jdbc.Driver'. This is deprecated. The new driver class is `com.mysql.cj.jdbc.Driver'. The driver is automatically registered via the SPI and manual loading of the driver class is generally unnecessary.
二、如果MySQL数据库的时区没有更改,在访问数据库时还可能出现以下异常:
The server time zone value 'Öйú±ê׼ʱ¼ä' is unrecognized or represents more than one time zone
解决办法,登录MySQL数据库设置时区: