2

I'm trying to connect my spring boot application with MySQL server.

I have followed the documentation properly but still, I'm getting some issue in connection Following exception is throwing every time

com.mysql.jdbc.exceptions.jdbc4.MySQLNonTransientConnectionException: Could not create connection to database server.
3
  • Is your mysql server up and running? Commented Jul 9, 2018 at 10:32
  • Are you able to connect to your mysql server using workbench or any other source apart from your application? Commented Jul 9, 2018 at 10:34
  • I'm able to connect with MySQL server through workbench eve. Commented Jul 9, 2018 at 17:16

2 Answers 2

4

In order for me to get around this error I have to log into MySql with the username & password stored in my application.properties file using MySql Workbench. After doing so the error no longer occurs. This only happens when trying to Run my spring boot project after restarting MySql server.

UPDATE: Adding "&allowPublicKeyRetrieval=true" to my spring.datasource.url in the application.properties file solved the problem. I figured this out after I noticed another error in the logs: "MySQL Public Key Retrieval is not allowed"

spring.datasource.url=jdbc:mysql://localhost:3306/db_example?autoReconnect=true&useSSL=false&allowPublicKeyRetrieval=true

Sign up to request clarification or add additional context in comments.

Comments

1

First of all restart MySQL server and retry again... If it is not...

Did you add application.properties details and JPA, MySQL dependency? Please Could you show pom.xml file and application.properties file.

appication.properties

spring.mvc.view.prefix=/WEB-INF/JSP/ #jsp file path
spring.mvc.view.suffix=.jsp

#Hibernate
spring.datasource.url=jdbc:mysql://localhost:3306/testdb?useSSL=false
spring.datasource.driver-class-name=com.mysql.jdbc.Driver
spring.datasource.username=root
spring.datasource.password=root
spring.jpa.generate-ddl=true

#JPA
spring.jpa.hibernate.ddl-auto=update
spring.jpa.show-sql=true
spring.jpa.properties.hibernate.dialect = org.hibernate.dialect.MySQL5Dialect

pom.xml

<dependency>
     <groupId>mysql</groupId>
     <artifactId>mysql-connector-java</artifactId>
     <scope>runtime</scope>
</dependency>
<dependency>
     <groupId>org.springframework.boot</groupId>
     <artifactId>spring-boot-starter-data-jpa</artifactId>
</dependency>

Thank you...!

1 Comment

I have done restarting the server and my application.properties and pom.xml matches the same.

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.