[Fix] Spring Boot: java.sql.SQLSyntaxErrorException: Unknown database

java.sql.SQLSyntaxErrorException: Unknown database 'myDB'

java.lang.IllegalStateException: Failed to execute CommandLineRunner
	at org.springframework.boot.SpringApplication.callRunner(SpringApplication.java:772) 

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.


  • Make sure you have provided the right database name in the application.properties file.
  • 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.
Spring Boot Project MySQL Configuration File Setup Example

Have Questions? Post them here!