java.sql.SQLSyntaxErrorException: Unknown database 'myDB'
java.lang.IllegalStateException: Failed to execute CommandLineRunner
at org.springframework.boot.SpringApplication.callRunner(SpringApplication.java:772)
~[spring-boot-3.0.5.jar:3.0.5]
Caused by: org.springframework.jdbc.CannotGetJdbcConnectionException: Failed to obtain JDBC Connection
...
Caused by: java.sql.SQLSyntaxErrorException: Unknown database 'myDB'
at com.mysql.cj.jdbc.exceptions.SQLError.createSQLException(SQLError.java:120)
... 22 common frames omitted
If you provide a wrong or incorrect Database name in your Spring Boot project application.properties file you are bound to get the Unknown database exception.
Fix/Solutions
- Make sure you have provided the right database name in the application.properties file.
spring.datasource.url=jdbc:mysql://localhost/myDB - Connect to the database and check if you have the database present. Make use of the show databases; query to check.
- Make sure that you are connecting to the right Database server, it could be so that you are in the wrong database (eg Staging/UAT instead of Prod)
- Check with the DBA that you have access to the database.

Provide Feedback For This Article
We take your feedback seriously and use it to improve our content. Thank you for helping us serve you better!
😊 Thanks for your time, your feedback has been registered!
Comments & Discussion
Facing issues? Have questions? Post them here! We're happy to help!