SpringBoot连接数据库报错:Access denied for user 'root'@'localhost' (using password: YES)

springboot项目连接数据库的时候报错,大概意思是被拒绝访问了

妈耶要吐血了,找了一上午,修改了有的说用户名用root可能会报错我把用户名改了,有的说权限不够,我改了访问mysql的权限都没什么用,最后看了一个大佬的博客才知道是因为配置文件格式的问题,如果用properties配置是没有问题的,但是用yml就会报错。

这是我之前的application.yml中数据库的配置,看起来一点毛病都没有,但是死活不对。

spring:
  datasource:
    driver-class-name: com.mysql.cj.jdbc.Driver
    url: jdbc:mysql://localhost:3306/mybatis?useSSL=true&useUnicode=true&characterEncoding=UTF-8&serverTimezone=UTC
    username: wanide
    password: 000000

下面这样就对了,给六个0加上双引号,这样获取到的密码才不会错!!!

spring:
  datasource:
    driver-class-name: com.mysql.cj.jdbc.Driver
    url: jdbc:mysql://localhost:3306/mybatis?useSSL=true&useUnicode=true&characterEncoding=UTF-8&serverTimezone=UTC
    username: wanide
    password: "000000"

绝了绝了,tui!

发布了322 篇原创文章 · 获赞 61 · 访问量 7万+

猜你喜欢

转载自blog.csdn.net/wan_ide/article/details/105118092