SpringBoot 连接mysql数据库踩坑总结

SpringBoot 连接mysql数据库踩坑总结

(一)SQLException:无法加载身份验证插件“caching_sha2_password”。

如下报错:

 ### The error may involve com.course.getUserCount ### The error occurred while executing a query ### Cause: org.springframework.jdbc.CannotGetJdbcConnectionException: Could not get JDBC Connection; nested exception is java.sql.SQLException: Unable to load authentication plugin 'caching_sha2_password'.

这是因为mysql8.0驱动已经更新适配了caching_sha2_password 的密码规则,这个时候需要在你的maven项目里面引入依赖:

    <groupId>mysql

    <artifactId>mysql-connector-java

    <version>8.0.11

</dependency>

然后,重新启动java服务,再次访问即可。

(二)SQLSyntaxErrorException:未知数据库'course&servertimezone=utc'

如下报错:

### Cause: org.springframework.jdbc.CannotGetJdbcConnectionException: Could not get JDBC Connection; nested exception is java.sql.SQLSyntaxErrorException: Unknown database 'course&servertimezone=utc'

这是因为配置文件里面需要添加时区和编码方式。

url: jdbc:mysql://localhost:3306/course?useUnicode=true&characterEncoding=utf8&serverTimezone=UTC

改成示例配置即可。

©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容