LedBaron
LedBaron

Reputation: 79

Connection to MYSQL database failing with spring boot (Web application)

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

Upvotes: 1

Views: 1895

Answers (2)

mengjiann
mengjiann

Reputation: 285

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.

Upvotes: 0

shahaf
shahaf

Reputation: 4973

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

Upvotes: 1

Related Questions