A shocking number of first Spring Boot and MySQL projects never get past startup. The app dies with a wall of red text, and the beginner is stuck before writing a single query. I have watched this happen in every project lab I have been in, and the fix is almost always one of the same five problems. Here they are, with the fix for each.
Key takeaways
- "Failed to configure a DataSource" means Spring Boot could not build a connection at all: the MySQL driver dependency is missing or the connection properties are misspelled; your pom.xml needs both JPA and the driver.
- "Access denied for user 'root'@'localhost'" means MySQL is running and reachable but rejected the credentials: verify the username and password with the MySQL client directly before touching Spring.
- "Unknown database" means the database itself does not exist: Spring Boot can create tables with
ddl-autobut never creates the database; create it once withCREATE DATABASE. - "Communications link failure" means the driver could not reach MySQL: check the server is running, the port (3306 by default), and that the JDBC URL points at the right host.
- Timezone and SSL warnings (like "The server time zone value is unrecognized") are fixed by naming the timezone explicitly in the connection URL.
Error 1: "Failed to configure a DataSource"
This is the most common one, and it means Spring Boot could not build a database connection at all. Two usual causes: the MySQL driver dependency is missing, or the connection properties are misspelled. Your pom.xml needs both JPA and the driver:
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-jpa</artifactId>
</dependency>
<dependency>
<groupId>com.mysql</groupId>
<artifactId>mysql-connector-j</artifactId>
<scope>runtime</scope>
</dependency>
Then check application.properties. The correct keys are spring.datasource.url, spring.datasource.username, and spring.datasource.password. I have seen spring.data.url and spring.datasource.jdbc-url fail silently too many times. One misspelled key and you are back at the red wall.
Error 2: "Access denied for user 'root'@'localhost'"
Good news disguised as bad news: this error means MySQL is running and Spring reached it, but the credentials were rejected. The fix is to verify the username and password with the MySQL client directly, before touching Spring:
mysql -u root -p
If the client rejects you too, the password in your properties file is wrong, full stop. If the client accepts you but Spring does not, look for stray spaces or quotes around the values in application.properties, or a second properties file overriding the first. During development, keep credentials in environment variables rather than committing them to Git; it also makes this class of mistake easier to spot.
Error 3: "Unknown database 'hoteldb'"
Spring Boot does not create the database for you. It can create tables inside a database with ddl-auto, but the database itself must exist first. Create it once:
CREATE DATABASE hoteldb;
This error usually appears after a rename: you changed the database name in your URL but forgot to create the new one. If you keep one SQL setup script next to your project and run it before the first launch, this error disappears forever.
Error 4: "Communications link failure"
This one means the driver could not reach MySQL at all. Walk the checklist in order: is the MySQL server actually running, is it listening on the port in your URL (3306 by default), and does your URL point at the right host? A URL like jdbc:mysql://localhost:3306/hoteldb fails if the server is stopped, bound to a different port, or running on a remote machine you forgot about. On a fresh install, the single most likely cause is simply that the MySQL service was never started.
A useful trick is to test the connection outside Spring entirely. If you can connect with the MySQL client using mysql -h localhost -P 3306 -u root -p but Spring cannot, the problem is in your URL or properties, not the server. If even the client fails, fix the server first: start the service, check that it listens on 3306, and confirm no firewall is blocking local connections. Separating "can I reach the server" from "is my Spring config right" cuts the debugging space in half.
Error 5: timezone and SSL warnings
Sometimes the app starts but the logs scream. The classic warning is The server time zone value '...' is unrecognized, which the connector resolves if you name a timezone explicitly:
spring.datasource.url=jdbc:mysql://localhost:3306/hoteldb?serverTimezone=UTC
The other warning is about SSL: the connector wants an encrypted connection and your local MySQL does not have one. On a local development machine you can silence it with useSSL=false on the URL. Keep that off in production; warnings you silence in development have a way of following you.
One more noisy startup line worth knowing: Hibernate logging that the connection pool started and added a connection is good news, it means the pool reached MySQL. A "connection is not available" message later means queries are waiting too long for a free connection, which usually points at an unclosed transaction or a slower query than you expected, not at the connection config.
A working config to copy
Here is the full set of properties that a working local setup boils down to. Adjust the database name, user, and password to your machine:
spring.datasource.url=jdbc:mysql://localhost:3306/hoteldb
spring.datasource.username=root
spring.datasource.password=root
spring.datasource.driver-class-name=com.mysql.cj.jdbc.Driver
spring.jpa.hibernate.ddl-auto=update
spring.jpa.show-sql=true
The ddl-auto=update line tells Hibernate to create and update tables as your entities change, which is perfect for development and must stay out of production. show-sql=true prints every query to the console, which is the fastest way to learn what your repositories are actually doing. With this config and the checklist above, connection errors stop being a wall and become a five-minute detour.