用户访问被拒绝 - 云 SQL

Access denied for user - CLOUD SQL

我正在尝试将 springboot 项目连接到 CLOUD SQL 数据库,但出现错误:

com.mysql.cj.exceptions.CJException: Access denied for user 'user'@'IP' (using password: YES).

SQL State : 08001 Error Code : 0 Message : Could not create connection to database server. Attempted reconnect 3 times. Giving up.

我尝试使用 mysql-client 和相同的用户 ans 密码连接到这个 CloudSQL 实例,它运行良好。

这是我正在使用的 springboot conf:

spring:
  datasource:
    url: jdbc:mysql://INSTANCE_IP/DB_NAME?useUnicode=true&characterEncoding=UTF-8&useJDBCCompliantTimezoneShift=true&useLegacyDatetimeCode=false&serverTimezone=UTC&autoReconnect=true&useSSL=false
    username: USERNAME
    password: PASSWORD

有没有人知道我做错了什么?

这是一个 MySQL 异常,在您输入错误的用户名或密码时发生。有详细的解释here

我还建议查看 Cloud SQL JDBC Socket Factory,它可以帮助 Java 用户连接到云 SQL。