Springboot连接MySQL8.0出现的问题

以前用的是5.7版本的MySQL,在学习实践Springboot的时候顺带升级了一下8.0,遇到了一些坑,在这记录一下,有碰到同类问题的童鞋需要自取。

使用 navicat连接发现报错1251- Client does not support authentication protocol 错误

这个笔者查询资料发现是新版本的加密规则变了,在mysql8之后,加密规则是caching_sha2_password,之前的是mysql_native_password,所以解决办法要不就是升级navicat要不就是修改加密规则。

这里修改加密规则:

1.进入MySQL的bin目录打开CMD,然后输入mysql -u root -p,输入密码

2.然后输入

ALTER USER 'root'@'localhost' IDENTIFIED BY 'password' PASSWORD EXPIRE NEVER; #修改加密规则

ALTER USER 'root'@'localhost' IDENTIFIED WITH mysql_native_password BY '输入你的密码'; #更新一下用户的密码 

FLUSH PRIVILEGES; #刷新权限

Mysql8.0)Could not create connection to database server - java mysql connector

这是因为没有更新驱动的原因,在Maven中更新下mysql-connector的版本

<!-- MySQL 连接驱动依赖 -->
<dependency>
    <groupId>mysql</groupId>
    <artifactId>mysql-connector-java</artifactId>
    <version>8.0.11</version>
</dependency>

<!--properties文件中更改driver-->
spring.datasource.driver-class-name=com.mysql.cj.jdbc.Driver

使用JDBC连接MySql时出现:The server time zone value '�й���׼ʱ��' is unrecognized or represents more than one time zone. You must configure either the server or JDBC driver (via the serverTimezone configuration

这是MyBatis时区错误,在链接库的url中加serverTimezone=UTC

spring.datasource.url=jdbc:mysql://localhost:3306/axin?useUnicode=true&characterEncoding=utf8&serverTimezone=UTC
原文地址:https://www.cnblogs.com/keeya/p/9786403.html