spring boot连接mysql报错:
Description:
Failed to configure a DataSource: 'url' attribute is not specified and no embedded datasource could be configured.
Reason: Failed to determine a suitable driver class
java.sql.SQLException: The server time zone value '�й���ʱ��' is unrecognized or represents more than one time zone.
在pom文件中加入的MySQL依赖项为:
<!-- mysql -->
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-jdbc</artifactId>
</dependency>
application.propertites文件配置为:
#mysql配置信息
spring.datasource.url=jdbc:mysql://localhost:3306/test
spring.datasource.username=root
spring.datasource.password=songwei123
spring.datasource.driver-class-name=com.mysql.cj.jdbc.Driver
报错原因:
数据库url配置不够详细,尤其缺少时区(time zone)信息。
修改方法:
在application.propertities文件MySQL的配置信息中,数据库的连接路径中添加时区信息:
spring.datasource.url=jdbc:mysql://localhost:3306/test?serverTimezone= Asia/Shanghai
建议将连接路径信息写得尽量详细,如加入编码格式等信息:
spring.datasource.url=jdbc:mysql://localhost:3306/test?useUnicode=true&characterEncoding=utf8&useSSL=false&serverTimezone= Asia/Shanghai
通过以上修改,成功解决MySQL连接时的报错。
版权声明:本文为博主原创文章,禁止转载
作者博客:codesong.cn
updated: 2019-10-24 15:26:30