gpt4 book ai didi

java - Spring Boot 与 MYSQL 数据库的连接失败(Web 应用程序)

转载 作者:行者123 更新时间:2023-11-29 17:39:56 30 4
gpt4 key购买 nike

我正在尝试使用 MySQL 服务器创建 OAuth2 登录功能。

我在尝试运行 Spring Web 应用程序时收到此错误。我在尝试将应用程序与 MySQL 服务器连接时遇到了几个问题,问题不在于 SQL 服务器名称的拼写错误。

2018-04-27 18:39:52.883  WARN 62329 --- [           main] o.h.e.j.e.i.JdbcEnvironmentInitiator     : HHH000342: Could not obtain connection to query metadata : Unknown database 'test'
2018-04-27 18:39:52.895 INFO 62329 --- [ main] org.hibernate.dialect.Dialect : HHH000400: Using dialect: org.hibernate.dialect.MySQL5Dialect
2018-04-27 18:39:52.916 INFO 62329 --- [ main] o.h.e.j.e.i.LobCreatorBuilderImpl : HHH000422: Disabling contextual LOB creation as connection was null
2018-04-27 18:39:53.464 INFO 62329 --- [ main] org.hibernate.tool.hbm2ddl.SchemaUpdate : HHH000228: Running hbm2ddl schema update

应用程序属性:

server.port=8081
server.context-path=/auth
security.basic.enable=false
spring.datasource.url=jdbc:mysql://localhost:3306/test
spring.datasource.username=root
spring.datasource.password =password
spring.datasource.testWhileIdle=true
spring.datasource.validationQuery=SELECT 1
spring.jpa.show-sql=true
spring.jpa.hibernate.ddl-auto=update
spring.jpa.hibernate.naming-strategy=org.hibernate.cfg.ImprovedNamingStrategy
spring.jpa.properties.hibernate.dialect=org.hibernate.dialect.MySQL5Dialect

当我使用空白用户名和密码运行应用程序时,我收到此错误:

2018-04-27 18:42:37.225  WARN 62332 --- [           main] o.h.e.j.e.i.JdbcEnvironmentInitiator     : HHH000342: Could not obtain connection to query metadata : Access denied for user ''@'localhost' (using password: NO)
2018-04-27 18:42:37.237 INFO 62332 --- [ main] org.hibernate.dialect.Dialect : HHH000400: Using dialect: org.hibernate.dialect.MySQL5Dialect
2018-04-27 18:42:37.256 INFO 62332 --- [ main] o.h.e.j.e.i.LobCreatorBuilderImpl : HHH000422: Disabling contextual LOB creation as connection was null
2018-04-27 18:42:37.712 INFO 62332 --- [ main] org.hibernate.tool.hbm2ddl.SchemaUpdate : HHH000228: Running hbm2ddl schema update

最佳答案

它告诉你为什么未知数据库'test'你应该创建一个数据库'test'或使用spring.jpa.hibernate.ddl-auto=create这将创建数据库即使存在,它也会覆盖任何存储的数据

您还可以在数据库网址中使用createDatabaseIfNotExist=true,例如

spring.datasource.url=jdbc:mysql://localhost:3306/test?createDatabaseIfNotExist=true

言出必行

关于java - Spring Boot 与 MYSQL 数据库的连接失败(Web 应用程序),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50066965/

30 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com