当前位置: 代码迷 >> 综合 >> errorCode 1045,state 28000: Access denied for user ‘mysql‘@‘localhost‘ (using password: YES)
  详细解决方案

errorCode 1045,state 28000: Access denied for user ‘mysql‘@‘localhost‘ (using password: YES)

热度:67   发布时间:2024-02-11 12:51:20.0

errorCode 1045,state 28000: Access denied for user ‘mysql’@‘localhost’ (using password: YES)

springboot连接mysql的时候出现登录失败的错误

errorCode 1045,state 28000 java sql.SQLException:Access denied for user 'root'@'localhost'

原因是yml配置文件中密码没有使用引号。
第一:在密码上加上单引号

spring:datasource:url: jdbc:mysql:jdbc:mysql://localhost:3306/springcloud-01?serverTimezone=UTC&useUnicode=true&characterEncoding=utf-8&useSSL=falseusername: rootpassword: '24425'driver-class-name: com.mysql.jdbc.Drivertype: com.alibaba.druid.pool.DruidDataSource

可能会不起作用,我就是,我的springboot版本是2.2.5,如果不起作用就只能将数据源的配置写在properties的配置文件下了。

spring.datasource.type=com.alibaba.druid.pool.DruidDataSource
spring.datasource.url=jdbc:mysql://localhost:3306/springcloud-01?serverTimezone=UTC&useUnicode=true&characterEncoding=utf-8&useSSL=false
spring.datasource.driver-class-name=com.mysql.jdbc.Driver
spring.datasource.password=24425
spring.datasource.username=root

由于=SpringBoot会全部加载配置文件并互补配置,所以只需要改动datasource的配置就行了

  相关解决方案