Error
Error Code: 1298

MySQL Error 1298: Invalid Time Zone Specified

📦 MySQL
📋

Description

MySQL Error 1298 indicates that the database server encountered a time zone name it does not recognize or that is incorrectly formatted. This error commonly occurs when a client connection, a session variable, or the server configuration attempts to set a time zone that is not loaded or valid within the MySQL system tables.
💬

Error Message

Unknown or incorrect time zone: '%s'
🔍

Known Causes

4 known causes
⚠️
Missing Time Zone Data
The MySQL server's internal time zone tables (e.g., `mysql.time_zone`) have not been properly loaded or initialized, preventing it from resolving named time zones.
⚠️
Incorrect Time Zone Name
The requested time zone name (e.g., 'America/NewYork' instead of 'America/New_York') is misspelled, uses an unsupported format, or does not exist in MySQL's loaded time zone data.
⚠️
Unsupported System Time Zone
If MySQL is configured to use the operating system's time zone, the system's configured time zone might not be recognized or supported by the MySQL server's internal time zone definitions.
⚠️
Client/Session Time Zone Setting
A client application or a `SET time_zone` statement within a specific database session attempted to set an invalid or unknown time zone, causing the operation to fail.
🛠️

Solutions

4 solutions available

1. Set the Global Time Zone easy

Directly configure MySQL to use a known, valid time zone.

1
Connect to your MySQL server as a user with sufficient privileges (e.g., root).
2
Execute the following SQL command to set the global time zone. Replace 'UTC' with a valid time zone name from MySQL's `mysql_tzinfo_to_sql` output or a standard IANA time zone name (e.g., 'America/New_York', 'Europe/London').
SET GLOBAL time_zone = 'UTC';
3
Verify the global time zone setting.
SELECT @@global.time_zone;
4
For the change to affect all existing connections, you might need to restart the MySQL server or have clients reconnect.

2. Set the Session Time Zone easy

Temporarily set the time zone for the current connection.

1
Connect to your MySQL server.
2
Execute the following SQL command to set the time zone for the current session. Replace 'UTC' with a valid time zone name.
SET SESSION time_zone = 'UTC';
3
Verify the session time zone setting.
SELECT @@session.time_zone;
4
This change is only effective for the current connection. New connections will use the global time zone setting unless explicitly set.

3. Update MySQL Time Zone Data medium

Ensure MySQL has the latest time zone information, especially if using older versions or custom time zone configurations.

1
Locate the `mysql_tzinfo_to_sql` utility. This is usually found in the MySQL installation directory or can be downloaded from the MySQL website.
2
Run the utility to generate SQL statements for populating the time zone tables in your MySQL database. You'll typically need to specify the path to the IANA time zone data files (often found in `/usr/share/zoneinfo` on Linux systems). This command may require root privileges.
sudo mysql_tzinfo_to_sql /usr/share/zoneinfo | mysql -u root -p mysql
3
After running the update, restart the MySQL server to ensure the new time zone information is loaded.
sudo systemctl restart mysql
4
Once the server is restarted, you can set the global or session time zone as described in the previous solutions.

4. Configure Time Zone in MySQL Configuration File medium

Permanently set the default time zone for the MySQL server by modifying its configuration.

1
Locate your MySQL configuration file. Common locations include `/etc/my.cnf`, `/etc/mysql/my.cnf`, or a file within `/etc/mysql/conf.d/`.
2
Open the configuration file using a text editor with administrative privileges (e.g., `sudo nano` or `sudo vi`).
3
Add or modify the `time_zone` setting under the `[mysqld]` section. Replace 'UTC' with a valid time zone name.
[mysqld]
time_zone = 'UTC'
4
Save the changes to the configuration file.
5
Restart the MySQL server for the changes to take effect.
sudo systemctl restart mysql
6
Verify the global time zone setting after the restart.
SELECT @@global.time_zone;
🔗

Related Errors

5 related errors