Access denied for user 'root'@'localhost'

我遇到的问题是:服务器mysql能登录,项目无法用root登录,报错如上
解决:
创建一个新用户,授权刷新

  grant all privileges on *.* to 'root01'@'%' ;
  flush privileges;

java.sql.SQLNonTransientConnectionException: Public Key Retrieval is not allowed

解决:
在spring.datasource.url 添加

allowPublicKeyRetrieval=true

如:

spring:
  datasource:
    url: jdbc:mysql://localhost:3306/yourdatabase?useUnicode=true&characterEncoding=utf-8&useSSL=false&serverTimezone=GMT&allowPublicKeyRetrieval=true
    username: root
    password: 123456
    driver-class-name: com.mysql.cj.jdbc.Driver

此外还有时区问题,最终改为serverTimezone=GMT成功


标签: root, 部署, mysql, springboot, spring, jdbc, privileges, true, ubuntu20.04

相关文章推荐

添加新评论,含*的栏目为必填