您好, 欢迎来到 !    登录 | 注册 | | 设为首页 | 收藏本站

springboot工程中数据库的配置

bubuko 2022/1/25 19:23:03 java 字数 1305 阅读 774 来源 http://www.bubuko.com/infolist-5-1.html

在 application.properties 配置文件中添加 MySQL 数据库的相关配置: #mysql数据库连接 mysql 5 spring.datasource.driver-class-name=com.mysql.jdbc.Driver spring.datasource.url=j ...

在 application.properties 配置文件中添加 MySQL 数据库的相关配置:

mysql数据库连接

mysql 5
spring.datasource.driver-class-name=com.mysql.jdbc.Driver
spring.datasource.url=jdbc:mysql://localhost:3306/mybatis_plus
spring.datasource.username=root
spring.datasource.password=123456

mysql8以上(spring boot 2.1)
spring.datasource.driver-class-name=com.mysql.cj.jdbc.Driver
spring.datasource.url=jdbc:mysql://localhost:3306/mybatis_plus?serverTimezone=GMT%2B8
spring.datasource.username=root
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 ‘?D1ú±ê×?ê±??‘ is unrecognized or represents more

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

springboot工程中数据库的配置

原文:https://www.cnblogs.com/yxyuanxiang/p/13948093.html


如果您也喜欢它,动动您的小指点个赞吧

除非注明,文章均由 laddyq.com 整理发布,欢迎转载。

转载请注明:
链接:http://laddyq.com
来源:laddyq.com
著作权归作者所有。商业转载请联系作者获得授权,非商业转载请注明出处。


联系我
置顶