How to Configure CEST Timezone in MariaDB on AlmaLinux
How to Configure CEST Timezone in MariaDB on AlmaLinux
Setting the correct timezone in your database is essential for accurate time-based operations, especially when dealing with applications across multiple regions. If you're running MariaDB on AlmaLinux and need to configure it for Central European Summer Time (CEST), this guide will walk you through the process step-by-step—including how to resolve startup errors due to unrecognized timezones.
📍 Step 1: Set the System Timezone to CEST
First, ensure your AlmaLinux server is using the correct timezone at the OS level.
Check the current timezone:
timedatectl
Set the timezone to a CEST-compatible zone (e.g., Europe/Berlin):
sudo timedatectl set-timezone Europe/Berlin
Verify the change:
timedatectl
🛠 Step 2: Update MariaDB to Use the CEST Timezone
By default, MariaDB may not recognize named timezones like Europe/Berlin
unless you import system timezone data.
🧩 Load System Timezones into MariaDB
Run the following to import timezone data into MariaDB:
mysql_tzinfo_to_sql /usr/share/zoneinfo | mysql -u root -p mysql
This populates the
mysql
system database with time zone definitions from your operating system.
🧾 Step 3: Update the MariaDB Configuration File
Edit the MariaDB server configuration:
sudo nano /etc/my.cnf.d/server.cnf
Add the following line under the
[mysqld]
section:[mysqld] default_time_zone = 'Europe/Berlin'
⚠️ Ensure the timezone name exists in the
mysql.time_zone_name
table—otherwise, MariaDB will fail to start.- Save and close the file.
🔄 Step 4: Restart MariaDB and Verify
Restart the service:
sudo systemctl restart mariadb
If you encounter an error like:
ERROR: Fatal error: Illegal or unknown default time zone 'Europe/Berlin'
It means the timezone data wasn’t loaded properly. Revisit Step 2 to fix this.
Verify the configuration:
SHOW VARIABLES LIKE 'time_zone';
It should return:
+---------------+----------------+ | Variable_name | Value | +---------------+----------------+ | time_zone | Europe/Berlin | +---------------+----------------+
🧪 Optional: Set Timezone Per Session (No Restart Needed)
You can also apply a temporary timezone in MariaDB:
SET time_zone = 'Europe/Berlin';
Or use a fixed UTC offset for CEST:
SET time_zone = '+02:00';
This is useful for specific sessions or scripts.
✅ Final Notes
- Named timezones like
Europe/Berlin
are preferred, as they automatically adjust for daylight saving time. - Don’t forget to load system timezone data if MariaDB doesn't recognize your timezone.
- You do not need to restart your server to apply system-level timezone changes—MariaDB handles this dynamically.
By following these steps, you'll ensure your MariaDB instance is correctly aligned with CEST, helping to avoid bugs, inconsistencies, or confusion in time-sensitive operations.