0

I'm try to connect to a MySQL database using Spring Data JPA (in a Spring Boot application) and always the same error:

java.sql.SQLException: Access denied for user ''@'localhost' (using password: NO)

My application.properties looks like:

spring.datasource.url=jdbc:mysql://localhost:3306/demographics
spring.datasource.data-username=root
spring.datasource.data-password=root
spring.jpa.hibernate.ddl-auto=update

I know the url, username and password are good.

3 Answers 3

1

The problem is with creating connection with the database itself due to authentication. Execute this with command line or some tool like mysql workbench.

GRANT ALL PRIVILEGES ON *.* TO 'root'@'localhost' IDENTIFIED BY '%root%' WITH GRANT OPTION;
Sign up to request clarification or add additional context in comments.

1 Comment

ERROR 1064 (42000): You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'IDENTIFIED BY '%root%' WITH GRANT OPTION' I don't think IDENTIFIED BY is allowed in GRANT queries.
1

The Spring documentation for "Common Application Properties" states that spring.datasource.data-username is the user to execute DML scripts (if different). I think you are looking for:

spring.datasource.username = root
spring.datasource.password = root

Notice you don't need the data- part of the key.

Keep in mind that if you need different credentials for both, you must specify them accordingly, unless they are the same. Also, just make sure the user have the correct/required privileges to access the schema you are using.

Comments

0

it seems your account in the database does not require password so just put empty password in your property

spring.datasource.data-password=

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.