springboot中数据库的连接

mysql5.0

1、#mysql数据库连接
2、spring.datasource.driver-class-name=com.mysql.jdbc.Driver
 
3、spring.datasource.url=jdbc:mysql://localhost:3306xxxx
 
4、spring.datasource.username=root
 
5、spring.datasource.password=123456
 
mysql8.0
1、spring.datasource.driver-class-name=com.mysql.cj.jdbc.Driver
 
2、spring.datasource.url=jdbc:mysql://localhost:3306/xxxx?serverTimezone=GMT%2B8
 
3、spring.datasource.username=root
 
4、spring.datasource.password=123456
 

注意:

1、这里的 url 使用了 ?serverTimezone=GMT%2B8 后缀,因为Spring Boot 2.1 集成了 8.0版本的jdbc驱动,这个版本的 jdbc 驱动需要添加这个后缀,否则运行测试用例报告如下错误:

java.sql.SQLException: The server time zone value 'Öйú±ê׼ʱ¼ä' is unrecognized or represents more 

2、这里的 driver-class-name 使用了  com.mysql.cj.jdbc.Driver ,在 jdbc 8 中 建议使用这个驱动,之前的 com.mysql.jdbc.Driver 已经被废弃,否则运行测试用例的时候会有 WARN 信息

posted @ 2020-08-03 15:10  池三岁  阅读(674)  评论(0编辑  收藏  举报