hibernate 用户“hp '@'localhost'”访问被拒绝(使用密码:否)在SpringBoot应用程序中

tyu7yeag  于 2023-05-18  发布在  Spring
关注(0)|答案(2)|浏览(194)

尝试用我的SpringBoot应用程序连接MySQL服务器,但面临上述问题,有人能建议吗?

spring.datasource.url=jdbc:mysql://localhost:3306/myblog
spring.datasourse.username=Admin
spring.datasourse.password=Admin

spring.jpa.properties.hibernate.dailect=org.hibernate.dialect.MySQLDialect
spring.jpa.hibernate.ddl-auto=update

错误如下

java.sql.SQLException: Access denied for user 'hp'@'localhost' (using password: NO)
    at com.mysql.cj.jdbc.exceptions.SQLError.createSQLException(SQLError.java:130) ~[mysql-connector-j-8.0.33.jar:8.0.33]
    at com.mysql.cj.jdbc.exceptions.SQLExceptionsMapping.translateException(SQLExceptionsMapping.java:122) ~[mysql-connector-j-8.0.33.jar:8.0.33]
    at com.mysql.cj.jdbc.ConnectionImpl.createNewIO(ConnectionImpl.java:825) ~[mysql-connector-j-8.0.33.jar:8.0.33]
    at com.mysql.cj.jdbc.ConnectionImpl.<init>(ConnectionImpl.java:446) ~[mysql-connector-j-8.0.33.jar:8.0.33]
    at com.mysql.cj.jdbc.ConnectionImpl.getInstance(ConnectionImpl.java:239) ~[mysql-connector-j-8.0.33.jar:8.0.33]
    at com.mysql.cj.jdbc.NonRegisteringDriver.connect(NonRegisteringDriver.java:188) ~[mysql-connector-j-8.0.33.jar:8.0.33]
    at com.zaxxer.hikari.util.DriverDataSource.getConnection(DriverDataSource.java:121) ~[HikariCP-5.0.1.jar:na]
    at com.zaxxer.hikari.pool.PoolBase.newConnection(PoolBase.java:359) ~[HikariCP-5.0.1.jar:na]
    at com.zaxxer.hikari.pool.PoolBase.newPoolEntry(PoolBase.java:201) ~[HikariCP-5.0.1.jar:na]
    at com.zaxxer.hikari.pool.HikariPool.createPoolEntry(HikariPool.java:470) ~[HikariCP-5.0.1.jar:na]
    at com.zaxxer.hikari.pool.HikariPool.checkFailFast(HikariPool.java:561) ~[HikariCP-5.0.1.jar:na]
    at co
btxsgosb

btxsgosb1#

错误显示用户为“hp”,但您的属性显示用户为“Admin”。密码也不匹配。您的应用程序使用了错误的凭据。两个密码的安全性都很差是另一个问题。

iaqfqrcu

iaqfqrcu2#

请检查datasource的拼写错误:

spring.jpa.hibernate.ddl-auto=update  
spring.datasource.url=jdbc:mysql://localhost:3306/db?createDatabaseIfNotExist=true   
spring.datasource.username=root  //your db user name  
spring.datasource.password=root  //your db user password 
spring.datasource.driverClassName=com.mysql.cj.jdbc.Driver
spring.jpa.database-platform=org.hibernate.dialect.MySQL8Dialect  
#If your MySql version 5 then use MySQL5Dialect
spring.data.jpa.repositories.enabled=true
spring.jpa.show-sql=true
spring.jpa.database=mysql

相关问题