Communications link failure ☕ Java

com.mysql.cj.jdbc.exceptions.CommunicationsException: Communications link failure

The MySQL JDBC driver couldn’t reach the database (or the connection dropped).

Seen on: Java

Meaning

“The last packet sent successfully to the server was 0 milliseconds ago” means it never connected: wrong host/port, DB down, firewall, or SSL negotiation issues. Non-zero means an idle connection was dropped.

Common causes

  • Wrong host/port or DB not running
  • Docker: localhost instead of service name
  • Firewall/security group
  • Idle connections killed (wait_timeout)
  • SSL/useSSL mismatch

⚡ Quick fix

  1. Verify the JDBC URL and that MySQL is reachable (telnet host 3306)
  2. Use the service name in containers
  3. Configure the pool (HikariCP maxLifetime < wait_timeout)

Detailed fix by platform

Java

  1. spring.datasource.hikari.max-lifetime=1700000

How to diagnose

  1. Last packet — 0 ms (never connected) or large (dropped)?
  2. Network — Reachable from the app host?

🧠 Still stuck? Analyze your error

Paste the full message, response headers or stack trace — we'll detect the platform and point to the most likely cause.