Denied error when connecting spring boot to mysql

Asked

Viewed 318 times

0

I’m trying to connect with mysql but only this error:

Caused by: org.flywaydb.core.internal.Exception.Flywaysqlexception: Unable to obtain Connection from database: Access denied for user '@'localhost' (using password: NO)

SQL State  : 28000
Error Code : 1045
Message    : Access denied for user ''@'localhost' (using password: NO)

I’ve been trying for hours to solve but I can’t. Because?

In the application.properties file

spring.datasource.url=jdbc:mysql://localhost/teste?createDatabaseIfNotExist=true&useSSL=false


spring.datasource.data-username=root
spring.datasource.data-password=1234

1 answer

1

The problem, apparently, is that you are setting the login only for the DML scripts, as correction should add the login data in the default DB, besides this you need to define the properties hibernate.dialect and ddl-auto and finally add &allowPublicKeyRetrieval=true in the DB url:

# URL para DB
spring.datasource.url=jdbc:mysql://localhost/teste?createDatabaseIfNotExist=true&useSSL=false&allowPublicKeyRetrieval=true

# Dados default de acesso para ao DB
spring.datasource.username  = root
spring.datasource.password  = 1234

# Dados para execuçao de scripts DML
# Somente é necessario se for diferente dos dados default
spring.datasource.data-username  = root
spring.datasource.data-password  = 1234

# Caso queria definir dados de login para execuçao de scripts DDL
# Assim como data-username somente é necessario se for diferente dos dados default
# spring.datasource.schema-username  = root
# spring.datasource.schema-password  = 1234

# The SQL dialect makes Hibernate generate better SQL for the chosen database
spring.jpa.properties.hibernate.dialect = org.hibernate.dialect.MySQL5Dialect

# Hibernate ddl auto (create, create-drop, validate, update)
spring.jpa.hibernate.ddl-auto = update


spring.jpa.properties.hibernate.jdbc.lob.non_contextual_creation=true

Browser other questions tagged

You are not signed in. Login or sign up in order to post.