以前用的是5.7版本的MySQL,在学习实践Springboot的时候顺带升级了一下8.0,使用教程
1、使用 navicat连接发现报错1251- Client does not support authentication protocol 错误
新版本的加密规则变了,在mysql8之后,加密规则是caching_sha2_password,之前的是mysql_native_password,所以解决办法要不就是升级navicat,要不就是修改加密规则。
1.1 这里修改加密规则:
1.进入MySQL的bin目录打开CMD,然后输入mysql -u root -p,输入密码
2.然后输入
1 2 3 4 5 |
|
ALTER USER 'root'@'localhost' IDENTIFIED BY 'password' PASSWORD EXPIRE NEVER;
#修改加密规则
ALTER USER 'root'@'localhost' IDENTIFIED WITH mysql_native_password BY '输入你的密码';
#更新一下用户的密码
FLUSH PRIVILEGES;
#刷新权限
2、Mysql8.0)Could not create connection to database server - java mysql connector
这是因为没有更新驱动的原因,在Maven中更新下mysql-connector的版本
1 2 3 4 5 6 7 8 9 |
|
3、使用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
1 |
|
4.application.yml文件配置
驱动为com.mysql.cj.jdbc.Driver
server:
port: 8080
context-path: /
spring:
datasource:
driver-class-name: com.mysql.cj.jdbc.Driver
url: jdbc:mysql://localhost:3306/db_jxc?serverTimezone=UTC&characterEncoding=utf8&useUnicode=true&useSSL=false
username: root
password: mysql@2021
jpa:
hibernate.ddl-auto: update
show-sql: true
thymeleaf:
cache: false
devtools:
restart:
enabled: true #设置开启热部署