当前位置: 首页 > 知识库问答 >
问题:

java.sql.sqlexception:spring中的用户''@'localhost'(使用密码:NO)的访问被拒绝

黄英韶
2023-03-14

application.properties文件

spring.datasource.url=jdbc:mysql://127.0.0.1:3306/photo_app?useUnicode=true&characterEncoding=UTF-8&zeroDateTimeBehavior=CONVERT_TO_NULL&serverTimezone=GMT
spring.datasource.data-username=suyash
spring.datasource.data-password=suyash
spring.jpa.hibernate.ddl-auto=update

SQL异常:

null

连接到查询元数据查询:

2019-11-17 12:20:32.501警告4912---[main]O.H.E.J.E.I.JDBCEnvironmentInitiator:hhh000342:无法获得查询元数据的连接:用户“@'localhost”访问被拒绝(使用密码:NO)2019-11-17 12:20:32.503警告4912---[main]ConfigServletWebServerApplicationContext:上下文初始化期间遇到异常-取消刷新尝试:org.SpringFramework.Beans.Factory.BeanCreationException:创建类路径资源嵌套异常为org.hibernate.service.spi.serviceException:无法创建请求的服务[org.hibernate.engine.jdbc.env.spi.jdbcEnvironment]2019-11-17 12:20:32.505信息4912---[main]o.apache.catalina.core.StandardService:正在停止服务[Tomcat]2019-11-17 12:20:32.515信息4912---[main]ConditionEvaluationReportLoggingListener:

应用程序上下文错误:

启动ApplicationContext时出错。若要显示条件报告,请在启用“调试”的情况下重新运行应用程序。2019-11-17 12:20:32.520错误4912--[main]O.S.Boot.SpringApplication:应用程序运行失败

null

共有2个答案

荀裕
2023-03-14

这样添加名称和密码成功了

# Connection url for the database "photo_app"
spring.datasource.url = jdbc:mysql://localhost:3306/photo_app
# Username and password
spring.datasource.username = suyash
spring.datasource.password = suyash
# Show or not log for each sql query
spring.jpa.show-sql = true
spring.jpa.hibernate.ddl-auto = update
# Naming strategy
spring.jpa.hibernate.naming-strategy = org.hibernate.cfg.ImprovedNamingStrategy
# Allows Hibernate to generate SQL optimized for a particular DBMS
spring.jpa.properties.hibernate.dialect = org.hibernate.dialect.MySQL5Dialect
束阳旭
2023-03-14

步骤1:

sudo mysql

第二步:检查您的密码。它可能是空的或有不同的东西

SELECT user,authentication_string,plugin,host FROM mysql.user;

步骤3:设置密码

ALTER USER 'suyash'@'localhost' IDENTIFIED WITH mysql_native_password BY 'suyash';

步骤4:

FLUSH PRIVILEGES;

现在,尝试启动spring应用程序

 类似资料: