Keeping the database server time zone predictable prevents confusing timestamp drift in application logs, scheduled jobs, and user-visible date math when multiple regions touch the same data in MySQL or MariaDB.
Both engines maintain a global default time zone (@@global.time_zone) and a per-connection time zone (@@session.time_zone). The default for new connections is usually SYSTEM, which follows the host OS time zone (@@system_time_zone), and functions like NOW() return values in the session time zone.
Changing the server time zone affects how TIMESTAMP columns are converted on insert and select, while DATETIME values remain “as stored” without conversion. Global changes apply to new connections only, existing sessions keep their current session value, and named zones like America/New_York require populated time zone tables; a numeric offset like +00:00 works without extra tables and avoids daylight-saving surprises.
Recommendation: keep database servers in UTC (+00:00) and convert to local time in the application or reporting layer.
Steps to set the server time zone:
- Open a privileged mysql client session.
$ mysql -u root -p Enter password: Welcome to the MySQL monitor. Commands end with ; or \g. ##### snipped ##### mysql>
On many servers, sudo mysql or sudo mariadb replaces password auth for the local root account.
- Display the current global, session, and OS-derived time zone values.
mysql> SELECT @@global.time_zone AS global_tz, @@session.time_zone AS session_tz, @@system_time_zone AS system_tz; +-----------+------------+-----------+ | global_tz | session_tz | system_tz | +-----------+------------+-----------+ | SYSTEM | SYSTEM | UTC | +-----------+------------+-----------+ 1 row in set (0.00 sec)
- Set the server-wide default time zone to UTC using a numeric offset.
mysql> SET GLOBAL time_zone = '+00:00'; Query OK, 0 rows affected (0.00 sec)
Changing time_zone changes how TIMESTAMP values are interpreted and displayed for sessions that use the new setting.
- Set the current connection’s session time zone to match the new global default.
mysql> SET SESSION time_zone = '+00:00'; Query OK, 0 rows affected (0.00 sec)
Offsets like +02:00 do not track DST; use an IANA name like Europe/Berlin when DST-correct local time is required.
- Verify that the session reports UTC.
mysql> SELECT @@global.time_zone AS global_tz, @@session.time_zone AS session_tz, NOW() AS now_session, UTC_TIMESTAMP() AS now_utc; +-----------+------------+---------------------+---------------------+ | global_tz | session_tz | now_session | now_utc | +-----------+------------+---------------------+---------------------+ | +00:00 | +00:00 | 2025-12-12 22:35:10 | 2025-12-12 22:35:10 | +-----------+------------+---------------------+---------------------+ 1 row in set (0.00 sec)
- Exit the mysql client session.
mysql> EXIT Bye
- List the server option files that mysqld reads at startup.
$ mysqld --verbose --help 2>/dev/null | grep -A3 "Default options are read from" Default options are read from the following files in the given order: /etc/my.cnf /etc/mysql/my.cnf /usr/etc/my.cnf ~/.my.cnf ##### snipped #####
- Open the option file that contains the active [mysqld] section.
$ sudoedit /etc/my.cnf
Common locations include /etc/my.cnf, /etc/mysql/my.cnf, and /etc/mysql/mysql.conf.d/mysqld.cnf.
- Add a startup default time zone under [mysqld].
[mysqld] default-time-zone = "+00:00"
Incorrect options or typos can prevent mysqld from starting and cause downtime.
- Restart the database service to apply the option file change.
$ sudo systemctl restart mysql
The unit name is often mysql, mysqld, or mariadb depending on the package and distro.
- Confirm the persisted setting in a new connection.
$ mysql -u root -p -e "SELECT @@global.time_zone AS global_tz, @@system_time_zone AS system_tz;" Enter password: +-----------+-----------+ | global_tz | system_tz | +-----------+-----------+ | +00:00 | UTC | +-----------+-----------+
Troubleshooting
- Use a numeric offset like +00:00 when an error reports Unknown or incorrect time zone for a named value.
Named zones require loaded time zone tables; offsets work without extra tables.
- Load time zone tables when setting time_zone to an IANA name like America/New_York.
$ mysql_tzinfo_to_sql /usr/share/zoneinfo | mysql -u root -p mysql Enter password: ##### snipped #####
Importing time zone tables writes into the mysql system database and requires administrative privileges.
- Retry the named time zone once time zone tables are loaded.
mysql> SET GLOBAL time_zone = 'America/New_York'; Query OK, 0 rows affected (0.00 sec)
- Use an account with sufficient privileges when SET GLOBAL returns an access error.
MySQL 8 often requires SYSTEM_VARIABLES_ADMIN; MariaDB commonly requires SUPER.
Mohd Shakir Zakaria is a cloud architect with deep roots in software development and open-source advocacy. Certified in AWS, Red Hat, VMware, ITIL, and Linux, he specializes in designing and managing robust cloud and on-premises infrastructures.
Comment anonymously. Login not required.
