Connector/J cannot work out the MySQL server time zone
The server time zone value 'XXX' is unrecognized or represents more than one time zone.Short answer
Connector/J reads the server's time_zone or system_time_zone and tries to map it to a Java zone. A vendor abbreviation like CEST or an unusual name cannot be mapped. Set an explicit zone in the URL with connectionTimeZone, or serverTimezone on older drivers, or give the server a named zone.
Fix it fast
1Find out which cause you have
Ask the server what zone it reports. If time_zone is SYSTEM, the value comes from the operating system's system_time_zone.
SELECT @@global.time_zone, @@global.system_time_zone;2Match what you see, then jump to its fix
What does the error look like?
The server time zone value 'XXX' is unrecognized or represents more than one time zone.
Cause 1 of 2
The server reports an abbreviation Java cannot map
1Check
With connectionTimeZone=SERVER the driver detects the zone from the server variables. The documentation says this can fail mostly because time zone abbreviations are used.
SELECT @@session.time_zone, @@global.system_time_zone;2Fix
Tell the driver the zone explicitly, using a name java.time.ZoneId can parse such as UTC or Europe/Berlin. Prefer the actual zone your data uses.
# Connector/J 8.0.23 and newer
jdbc:mysql://db:3306/app?connectionTimeZone=UTC
# older drivers, still accepted as an alias
jdbc:mysql://db:3306/app?serverTimezone=UTC3Verify
Connect again; the exception is gone and a timestamp round-trips.
SELECT NOW(), UTC_TIMESTAMP();Confirmed by dev.mysql.com
Cause 2 of 2
You want the session itself to use that zone
1Check
connectionTimeZone alone does not change the MySQL session variable time_zone. Only forceConnectionTimeZoneToSession=true does, and it also changes NOW(), CURTIME() and CURDATE().
SELECT @@session.time_zone, NOW();2Fix
Set both properties if the session should follow the connection zone. A geographic name needs the server time zone tables loaded, an offset such as +00:00 does not.
jdbc:mysql://db:3306/app?connectionTimeZone=UTC&forceConnectionTimeZoneToSession=true3Verify
Compare the session zone and NOW() after reconnecting.
SELECT @@session.time_zone, NOW();Confirmed by dev.mysql.com
How do I stop it coming back?
- Run database servers on a named zone or UTC, never on a three-letter abbreviation.
- Put the connection time zone in configuration, not in code.
- Store instants in TIMESTAMP columns and keep the JVM and connection zone documented in the project README.
Sources
How was this page made?
I drafted this page with AI assistance from the official documents listed under Sources. Every cause above names the document that confirms it. I have not reproduced this fix on a machine of my own yet, so read it as documented guidance, not a test report. Found a mistake? Tell me.
Which stack is behind this page?
Projects of mine built on the same technologies:
- TaxiDexMy own multi-tenant taxi dispatch SaaS: API, dispatcher portal, driver and passenger apps, and the servers underneath.
- QistLockA NestJS and React SaaS driving an Android Device Owner agent that locks financed phones when payments lapse.
- ShopGoAn e-commerce aggregator with a Python scraping engine behind its catalog, past 10K Google Play downloads.
Related fixes
Databases
EntityNotFoundException when loading an entity that has a missing related row
ConstraintViolationException on an orphaned foreign key
EntityNotFoundException means Hibernate followed an id and no row was there.
3 causes, each with a fixDatabases
Hibernate fails on a CREATE or ALTER TABLE statement at startup
Error executing DDL "alter table events drop foreign key FKg0mkvgsqn8584qoql6a2rxheq" via JDBC Statement
Hibernate generated a CREATE, ALTER or DROP statement and MySQL refused it.
3 causes, each with a fixDatabases
MySQL Connector/J: EOFException, expected to read 4 bytes, read 0 bytes
Communications link failure
The MySQL server or something between you and it closed the connection, and the driver found out only when it tried to use it.
3 causes, each with a fixDatabases
Java cannot log in to MySQL 8: authentication plugin caching_sha2_password not supported
ERROR 2061 (HY000): Authentication plugin 'caching_sha2_password' reported error: Authentication requires secure connection.
MySQL 8 accounts use the caching_sha2_password plugin by default, and Connector/J releases before 8.0.9 cannot use it.
3 causes, each with a fixDatabases
MySQL refuses to delete a row because other rows point to it
SQLIntegrityConstraintViolationException: Cannot delete or update a parent row: a foreign key constraint fails
Error 1451 means at least one child row still references the parent row you are deleting or changing.
3 causes, each with a fixDatabases
JDBC cannot talk to MySQL: Communications link failure
The last packet sent successfully to the server was 0 milliseconds ago.
Communications link failure means the TCP link to MySQL could not be opened or was closed.
3 causes, each with a fix