Error
Error Code:
1298
MariaDB Error 1298: Unknown Time Zone Specified
Description
This error indicates that MariaDB cannot recognize or find the time zone specified in a query, configuration, or session variable. It typically occurs when a time zone name is misspelled, not loaded into the server's time zone tables, or the system's time zone is not properly configured. The database server fails to process operations dependent on the unrecognized time zone.
Error Message
Unknown or incorrect time zone: '%s'
Known Causes
4 known causesInvalid Time Zone Name
The time zone name provided in a SQL statement, session variable, or application connection string is misspelled or does not correspond to a recognized time zone.
Missing Time Zone Tables
The MariaDB server's internal time zone tables (e.g., 'mysql.time_zone_name') have not been populated or are incomplete, preventing the server from resolving time zone names.
System Time Zone Discrepancy
The operating system's time zone setting is not recognized by MariaDB, or there's a conflict between the system's time zone and the database's expected time zone handling.
Application Configuration Error
An application is attempting to set an unrecognized or improperly formatted time zone for the database connection, leading to a server-side rejection.
Solutions
4 solutions available1. Set the Global Time Zone Correctly easy
Update the MariaDB server's global time zone setting to a valid value.
1
Connect to your MariaDB 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 your desired valid time zone (e.g., 'America/New_York', 'Europe/London'). You can list available time zones by running `SELECT DISTINCT Olson_tz FROM mysql.time_zone;`.
SET GLOBAL time_zone = 'UTC';
3
To verify the change, run:
SELECT @@global.time_zone, @@session.time_zone;
4
Restart the MariaDB server for the change to take full effect across all connections.
2. Configure Time Zone in my.cnf/my.ini medium
Permanently set the time zone in the MariaDB configuration file.
1
Locate your MariaDB configuration file. This is typically `my.cnf` on Linux/macOS or `my.ini` on Windows. Common locations include `/etc/my.cnf`, `/etc/mysql/my.cnf`, or within the MariaDB installation directory.
2
Open the configuration file with a text editor.
3
Under the `[mysqld]` section, add or modify the `time_zone` setting. Replace 'UTC' with your desired valid time zone.
[mysqld]
time_zone = 'UTC'
4
Save the configuration file.
5
Restart the MariaDB server for the changes to be applied.
3. Set Time Zone for Specific Sessions easy
Temporarily set the time zone for the current client session.
1
Connect to your MariaDB server.
2
Execute the following SQL command to set the time zone for the current session. Replace 'UTC' with your desired valid time zone.
SET SESSION time_zone = 'UTC';
3
You can verify the session time zone with:
SELECT @@session.time_zone;
4
This change is only valid for the current connection and will be reset when the connection is closed.
4. Update Time Zone Information Files advanced
Ensure MariaDB has access to up-to-date time zone data.
1
MariaDB uses the system's time zone files or its own internal ones. If your time zone data is outdated, you might need to update it. On many Linux systems, this involves updating packages like `tzdata`.
sudo apt-get update && sudo apt-get upgrade tzdata # For Debian/Ubuntu
sudo yum update tzdata # For RHEL/CentOS/Fedora
2
After updating system time zone data, restart MariaDB.
3
If MariaDB is configured to use its own time zone tables (often populated from `mysql.time_zone` and `mysql.time_zone_name`), ensure these tables are populated correctly. You can check their contents with `SELECT * FROM mysql.time_zone;` and `SELECT * FROM mysql.time_zone_name;`.
4
If the tables are missing or incomplete, you may need to re-initialize them using the `mysql_tzinfo_to_sql` utility, which is usually found in your MariaDB client or server installation. Consult the MariaDB documentation for specific instructions on using this utility based on your operating system and MariaDB version.