hibernate数据库连接密码解析问题

38 阅读1分钟

遇到一个hibernate数据库连接密码解析问题,当时配置如下

spring:
  datasource:
    url: jdbc:mysql://localhost:3306/PaiSmart?useSSL=false&serverTimezone=UTC&allowPublicKeyRetrieval=true&characterEncoding=utf8
    username: root
    password: 1234
    driver-class-name: com.mysql.cj.jdbc.Driver
  jpa:
    hibernate:
      ddl-auto: update
    show-sql: true
    properties:
      hibernate:
        dialect: org.hibernate.dialect.MySQL8Dialect

本地直接启动会出现以下报错

[main] WARN org.hibernate.engine.jdbc.spi.SqlExceptionHelper - SQL Error: 1045, SQLState: 28000
ERROR org.hibernate.engine.jdbc.spi.SqlExceptionHelper - Access denied for user 'root'@'localhost' (using password: YES)

数据库连接,命令行、navicate都可以正常连接,但是还是尝试了多种方法包括了重启电脑、idea、升级mysql,更换数据库端口,检查root权限,防火墙配置端口,更换maven仓库,都没有查到点子上,后怀疑是密码解析格式问题,可能解析为了8进制,遂更改配置为一下

spring:
  datasource:
    url: jdbc:mysql://localhost:3306/PaiSmart?useSSL=false&serverTimezone=UTC&allowPublicKeyRetrieval=true&characterEncoding=utf8
    username: root
    password: "1234"
    driver-class-name: com.mysql.cj.jdbc.Driver
  jpa:
    hibernate:
      ddl-auto: update
    show-sql: true
    properties:
      hibernate:
        dialect: org.hibernate.dialect.MySQL8Dialect

直接搞成字符串之后就没有问题了