1

I am trying to create an OAuth2 login function using MySQL server.

I get this error when trying to run a Spring web application. I have faced several problems trying to connect the application with MySQL server and it's not the misspelling of the SQL server name that is the problem.

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

application.properties:

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

And when i run the application with a blank username and password i get this error:

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

2 Answers 2

1

it's telling you why Unknown database 'test' you should create a database 'test' or use spring.jpa.hibernate.ddl-auto=create this will create the database even if exists, it will override any data stored

you can also use createDatabaseIfNotExist=true in your database url like

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

it does what it says

Sign up to request clarification or add additional context in comments.

2 Comments

So the application runs now, thanks! Additional question: How do i access this "auto" created database so i can edit tables etc.?
@LedBaron basically you don't access this database and update tables you should do it using the entity definitions and init script, see the following baeldung.com/spring-boot-data-sql-and-schema-sql depends your os, but I suggest mysql workbench as the best tool to access the db dev.mysql.com/downloads/workbench
0

It will be easier to start off your development project using H2 embedded database. Embedded H2 db comes with a web console, which you can access the table created directly from a browser.

It is also an in-memory database where it will be a fresh db everything you start your spring boot app. You can use import.sql to preload it.

Here is a link you to explore. I always use it for starting off a new project and also good for learning.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.