Maaz Zindani

Loading the index…

↑↓ move↵ openesc close4072 pages
Databases and Redis

Connector/J cannot work out the MySQL server time zone

ErrorThe 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.

  • Applies to MySQL 8.4, MySQL Connector/J 8.4 and 9, Java 21
  • Updated
  • By Maaz Zindani, Senior Software Engineer

Fix it fast

  1. 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;
  2. 2Match what you see, then jump to its fix

    1. 1system_time_zone is something like CEST, PST or a local abbreviationThe server reports an abbreviation Java cannot mapFix
    2. 2The error is gone but NOW() or stored TIMESTAMP values are shiftedYou want the session itself to use that zoneFix

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=UTC

3Verify

Connect again; the exception is gone and a timestamp round-trips.

SELECT NOW(), UTC_TIMESTAMP();

Confirmed by dev.mysql.com

Did this fix it?

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=true

3Verify

Compare the session zone and NOW() after reconnecting.

SELECT @@session.time_zone, NOW();

Confirmed by dev.mysql.com

Did this fix it?

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:

Related fixes

Databases

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 fix

Next step

Want this handled for good?

I look after servers, apps and releases end to end. Tell me what keeps breaking.