All pages
Powered by GitBook
1 of 1

Loading...

Time Zones

Manage time zone settings in MariaDB, including the global server time zone, session time zone, and system time zone configurations.

MariaDB keeps track of several time zone settings.

Setting the Time Zone

The time_zone system variable is the primary way to set the time zone. It can be specified in one of the following formats:

  • The default value is SYSTEM, which indicates that the system time zone defined in the system variable will be used. Note that if you are using SYSTEM with replication in either statement or mixed mode, you MUST use the same value for system_time_zone on all replicas (otherwise TIMESTAMP columns will not replicate correctly). See below for more information.

  • An offset from , such as +5:00 or -9:00, can also be used.

  • If the time zone tables in the database were loaded, then a named time zone, such as America/New_York, Africa/Johannesburg, or Europe/Helsinki, is also permissible. See below for more information.

There are two time zone settings that can be set within MariaDB--the global server time zone, and the time zone for your current session. There is also a third time zone setting which may be relevant--the system time zone.

Global Server Time Zone

The global server time zone can be changed at server startup by setting the --default-time-zone option either on the command-line or in a server in an . For example:

The global server time zone can also be changed dynamically by setting the system variable as a user account that has the privilege. For example:

The current global server time zone can be viewed by looking at the global value of the system variable. For example:

Session Time Zone

Each session that connects to the server will also have its own time zone. This time zone is initially inherited from the global value of the system variable, which sets the session value of the same variable.

A session's time zone can be changed dynamically by setting the system variable. For example:

The current session time zone can be viewed by looking at the session value of the system variable. For example:

System Time Zone

The system time zone is determined when the server starts, and it sets the value of the system variable. The system time zone is usually read from the operating system's environment. You can change the system time zone in several different ways, such as:

  • If you are starting the server with , then you can set the system time zone with the --timezone option either on the command-line or in the [mariadbd-safe] in an . For example:

  • If you are using a Unix-like operating system, then you can set the system time zone by setting the TZ in your shell before starting the server. For example:

  • On some Linux operating systems, you can change the default time zone for the whole system by making the symbolic link point to the desired time zone. For example:

  • On some Debian-based Linux operating systems, you can change the default time zone for the whole system by executing the following:

  • On Linux operating systems that use , you can change the default time zone for the whole system by using the utility. For example:

Time Zone Effects

Time Zone Effects on Functions

Some functions are affected by the time zone settings. These include:

Some functions are not affected. These include:

Time Zone Effects on Data Types

Some data types are affected by the time zone settings.

  • - See for information on how this data type is affected by time zones.

  • - See for information on how this data type is affected by time zones.

mysql Time Zone Tables

The database contains a number of time zone tables:

By default, these time zone tables in the database are created, but not populated.

If you are using a Unix-like operating system, then you can populate these tables using the utility, which uses the data available on Linux, Mac OS X, FreeBSD and Solaris.

If you are using Windows, then you will need to import pre-populated time zone tables. These are available at .

Time zone data needs to be updated on occasion. When that happens, the time zone tables may need to be reloaded.

See Also

  • (video)

This page is licensed: CC BY-SA / Gnu FDL

UNIX_TIMESTAMP()
time_zone_transition_type
system_time_zone
System Time Zone
Coordinated Universal Time (UTC)
mysql
mysql Time Zone Tables
option group
option file
time_zone
SUPER
time_zone
time_zone
time_zone
time_zone
system_time_zone
mariadbd-safe
option group
option file
environment variable
/etc/localtime
systemd
timedatectl
NOW()
SYSDATE()
CURDATE()
CURTIME()
UTC_DATE()
UTC_TIME()
UTC_TIMESTAMP()
TIMESTAMP
TIMESTAMP: Time Zones
DATETIME
DATETIME: Time Zones
mysql
time_zone
time_zone_leap_second
time_zone_name
time_zone_transition
mysql
mariadb-tzinfo-to-sql
zoneinfo
MariaDB mirrors
LinuxJedi in Spacetime: Properly Handling Time and Date
[mariadb]
...
default_time_zone = 'America/New_York'
SET GLOBAL time_zone = 'America/New_York';
SHOW GLOBAL VARIABLES LIKE 'time_zone';
+---------------+--------+
| Variable_name | Value  |
+---------------+--------+
| time_zone     | SYSTEM |
+---------------+--------+
SET time_zone = 'America/New_York';
SHOW SESSION VARIABLES LIKE 'time_zone';
+---------------+--------+
| Variable_name | Value  |
+---------------+--------+
| time_zone     | SYSTEM |
+---------------+--------+
[mariadbd-safe]
timezone='America/New_York'
$ export TZ='America/New_York'
$ service mariadb start
$ sudo rm /etc/localtime
$ sudo ln -s /usr/share/zoneinfo/America/New_York /etc/localtime
sudo dpkg-reconfigure tzdata
sudo timedatectl set-timezone America/New_York