MSQL Workbench not being populated with table data for Spring Boot JPA Entity

Dog :

I have been trying to connect a Spring Boot application to MySQL workbench and have not been able to. My MySQL Workbench (version 8.0.13) server is running and it indicates the default localhost connection is on localhost 3306. I also have created a database in the workbench called TestSchema.

I have configured the Spring Boot application.properties to recognize this connection as follows:

spring.jpa.hibernate.ddl-auto=create
spring.datasource.url=jdbc:mysql://localhost:3306/TestSchema
spring.datasource.username=*****    
spring.datasource.password=*****
spring.datasource.driver-class-name=com.mysql.cj.jdbc.Driver
spring.jpa.properties.hibernate.dialect = org.hibernate.dialect.MySQL5Dialect
spring.jpa.database = MYSQL

which from my understanding is the correct way of configuring the application.

Finally, I have created a User table in the Spring Boot application with the @Entity annotation. Yet, when I run the Spring Boot application it gives me this error:

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

While that is the username I have configured, YES is not the password I provided in the application.properties file and is not my MySQL workbench password. How can I properly configure my Spring Boot application to recognize my MySQL Workbench and automatically populate the TestSchema database with the User @Entity JPA annotation?

Gaurav :

Conclusion of on-chat discussion.

As per the Spring Boot offical document JDBC driver will be autodetected.

spring.datasource.driver-class-name = # Fully qualified name of the JDBC driver. Auto-detected based on the URL by default.

Granting privilige to the MySQL user and using mysql_native_password for default authentication.

GRANT ALL PRIVILEGES ON * . * TO 'user_name'@'localhost'; 
ALTER USER 'user_name'@'localhost' IDENTIFIED WITH mysql_native_password BY 
'user_name';

Change in datasource URL due to error: java.sql.SQLNonTransientConnectionException: Public Key Retrieval is not allowed

If the user account uses sha256_password authentication, the password must be protected during transmission; TLS is the preferred mechanism for this, but if it is not available then RSA public key encryption will be used. To specify the server's RSA public key, use the ServerRSAPublicKeyFile connection string setting, or set AllowPublicKeyRetrieval=True to allow the client to automatically request the public key from the server.

spring.datasource.url=jdbc:mysql://localhost:3306/TestSchema?useUnicode=true&cha‌​racterEncoding=UTF-8&allowPublicKeyRetrieval=true&useSSL=false

AllowPublicKeyRetrieval=True could allow a malicious proxy to perform a MITM attack to get the plaintext password, so it is False by default and must be explicitly enabled.

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=131264&siteId=1