Software Development

How to fix the MySQL Could not create connection to database server error during setup?

BR Asked by Bradley Harrison · 12-10-2025
0 upvotes 14,312 views 0 comments
The question

I'm trying to connect my Java application to a local MySQL instance, but I keep hitting the "Could not create connection to database server" error. I've double-checked my username and password, and the MySQL service is definitely running on port 3306. Is this likely a driver version mismatch, a timezone configuration issue, or perhaps something related to the bind-address in my my.cnf file? I’m using Connector/J 8.0, and any help on the specific connection string parameters would be appreciated.

3 answers

0
KA
Answered on 14-10-2025

This error often occurs in MySQL 8.0+ because the driver requires an explicit server time zone or a specific SSL configuration. To fix this, try appending ?useSSL=false&serverTimezone=UTC to your JDBC connection URL. Additionally, ensure that your MySQL user has the correct privileges to connect from 'localhost' or '%'. If you are using an older version of the JDBC driver with a newer MySQL server, the authentication plugin (caching_sha2_password) might be causing the failure. Updating your Connector/J dependency to the latest version usually resolves the handshake issue. Lastly, verify that your firewall isn't blocking port 3306, even if you are connecting locally, as some security software can intercept these requests.

0
MA
Answered on 16-10-2025

Have you checked your my.ini or my.cnf file to see if the bind-address is set to 127.0.0.1? If it is, and you are trying to connect via the actual IP address of the machine instead of 'localhost', the server will reject the connection attempt immediately.

ST 18-10-2025

Marcus, that was a lifesaver! I was trying to connect using my local network IP while the server was restricted to the loopback address. For anyone else struggling, you can change the bind-address to 0.0.0.0 to allow connections from any interface, but please be careful with security if your server is exposed to the internet. After changing the config file, remember to restart the MySQL service for the changes to take effect, or you'll keep seeing the same error despite the "fix."

0
BR
Answered on 20-10-2025

You likely just need to add serverTimezone=UTC to your connection string. MySQL 8 is very strict about this, and the driver will fail to create a session if the zone isn't defined.

BR 21-10-2025

I agree with Brenda. I spent hours on this last month. It’s also worth checking if your MySQL service account has expired or if the "max_connections" limit has been reached on the server side, as both can trigger the same generic connection failure message in the Java console.

Share your thoughts

Your email address will not be published. Required fields are marked (*)

Professional Counselling Session

Still have questions?
Schedule a free counselling session

Our experts are ready to help you with any questions about courses, admissions, or career paths. Get personalized guidance from industry professionals.

Request a Call Back

Search Online

We Accept

We Accept

Follow Us

"PMI®", "PMBOK®", "PMP®", "CAPM®" and "PMI-ACP®" are registered marks of the Project Management Institute, Inc. | "CSM", "CST" are Registered Trade Marks of The Scrum Alliance, USA. | COBIT® is a trademark of ISACA® registered in the United States and other countries.

Book Free Session