
Fabian Tech Tips

The time zone configured in the /etc/my.cnf will need to be reinstated in the event of a server replacement or MariaDB reinstall.
Oct 13, 2024
2 min read
0
2
0
The time zone is configured in the /etc/my.cnf This will need reinstated in case of a server replacement or MariaDB reinstall.
/etc/my.cnf
## Timezone
default-time-zone='Europe/Dublin'
to complete the configuration execute
mysql_tzinfo_to_sql /usr/share/zoneinfo | mysql -u root mysql
Detailed Explanation of MySQL Timezone Configuration
File: /etc/my.cnf
Setting the Timezone:
[mysqld]
default-time-zone='Europe/Dublin'
Explanation: This line sets the default time zone for the MySQL server to ‘Europe/Dublin’. This ensures that all date and time functions will use this time zone unless overridden by a specific query.
Completing the Configuration:
mysql_tzinfo_to_sql /usr/share/zoneinfo | mysql -u root mysql
Explanation: This command loads the time zone information from the system’s zoneinfo database into MySQL. Here’s a breakdown:
mysql_tzinfo_to_sql /usr/share/zoneinfo: This part of the command converts the time zone data from the system’s zoneinfo files into a format that MySQL can understand.
|: This pipe symbol passes the output of the first command as input to the next command.
mysql -u root mysql: This part of the command connects to the MySQL server as the root user and imports the time zone data into the mysql database.
Steps to Follow:
Edit the Configuration File:
Open the /etc/my.cnf file in a text editor.
Add the line default-time-zone='Europe/Dublin' under the [mysqld] section.
Save and close the file.
Load Time Zone Data:
Open a terminal.
Execute the command: mysql_tzinfo_to_sql /usr/share/zoneinfo | mysql -u root mysql.
Restart MySQL Server:
Restart the MySQL server to apply the changes. This can typically be done with a command like sudo systemctl restart mysqld or sudo service mysql restart, depending on your system.
This configuration ensures that your MySQL server uses the ‘Europe/Dublin’ time zone by default and has the necessary time zone data loaded for accurate time-related functions.