Fix “ERROR 1298 (HY000): Unknown or incorrect time zone…” in MySQL

If you’re getting error 1298 that reads something like “ERROR 1298 (HY000): Unknown or incorrect time zone: ‘UTC’” in MySQL, it’s probably because you’re specifying a time zone name, but your MySQL installation hasn’t yet been configured for named time zones.

To fix this issue, be sure that your MySQL installation has been configured for named time zones.

Example of Error

Here’s an example of code that produces the error:

SET time_zone = 'UTC';

Result:

ERROR 1298 (HY000): Unknown or incorrect time zone: 'UTC'

In my case, I tried to set the time_zone variable to UTC but my system didn’t recognise that as a valid time zone.

Possible Causes

The cause of the above error is that my system hadn’t yet been configured for named time zones.

It could also be that you’re using an invalid time zone name.

Solution 1

The first solution is to configure MySQL for named time zones.

The MySQL installation process creates a bunch of time zone tables, but it does not populate them with any data. These tables are for holding information about time zone names, and we first need to populate them before we can use named time zones in MySQL.

The reason these tables are empty by default is because it’s usually better that the system handles the time zone, if possible. By leaving these tables empty, MySQL gives us the opportunity to leverage our system’s time zone information.

Fortunately the process of loading these tables is quick and easy. There’s a utility that allows us to do it all with a single line of code.

See How to Set Up Named Time Zones in MySQL for instructions on doing that. Once done, you’ll be able to convert between time zones using the time zone names.

Solution 2

Solution 2 is to ensure that you’re using the correct time zone name.

If your system has already been configured for named time zones, it’s possible that you’re trying to use an invalid time zone name (one that isn’t recognised by your system). This could be because you mistyped it, or it could be that your system simply doesn’t support that time zone.

For example, even when my system has been configured for named time zones, entering the following still produces an error:

SET time_zone = 'UFC';

Result:

ERROR 1298 (HY000): Unknown or incorrect time zone: 'UFC'

That’s because, although my system contains information about time zone names, it doesn’t contain information about the UFC time zone name.

In this case, I accidentally typed UFC instead of UTC.

Therefore, to fix this issue simply use the correct time zone name, and be sure that it’s one that your system recognises.

To check whether or not your system recognises a time zone name, you can query the mysql.time_zone_name table:

SELECT * 
FROM mysql.time_zone_name
WHERE NAME LIKE '%UTC%';

Result:

+---------+--------------+
| Name    | Time_zone_id |
+---------+--------------+
| Etc/UTC |          424 |
| UTC     |          593 |
+---------+--------------+

In this case, there are two named time zones that match my query.

Adjust the LIKE operator as needed.