简体   繁体   中英

How to fix this error in Spring Boot using Spring Data JPA and MySQL

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.

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;

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.

看来您在数据库中的帐户不需要密码,所以只需在您的媒体资源中输入空密码

spring.datasource.data-password=

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM