Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

MariaDB set timezone in config

How do I set the server timezone in the MariaDB configuration?

The only thing I can find in the documentation is using command-line flags, which I don't want to do.

default_time_zone, which works on vanilla MySQL, isn't recognized by MariaDB.

like image 771
user2562424 Avatar asked Oct 13 '14 22:10

user2562424


2 Answers

It is default-time-zone (- instead of _):

[server]
default-time-zone=+00:00
like image 62
Gergo Erdosi Avatar answered Sep 20 '22 17:09

Gergo Erdosi


Here is a complete summary collecting from above question and answers:

open

/etc/my.cnf.d/server.conf

change to example:

#
# These groups are read by MariaDB server.
# Use it for options that only the server (but not clients) should see
#
# See the examples of server my.cnf files in /usr/share/mysql/
#

# this is read by the standalone daemon and embedded servers
[server]
default-time-zone=-06:00

# this is only for the mysqld standalone daemon
[mysqld]

NOTE: for string

default-time-zone=-06:00 // this is equivalent to (america/edmonton)

You will need to figure out for your timezone to do so look up here https://en.wikipedia.org/wiki/List_of_tz_database_time_zones

Restart the mysql server:

service mariadb restart

Testing:

[smith@home my.cnf.d]# mysql -u smith -p
Enter password:
Welcome to the MariaDB monitor.  Commands end with ; or \g.
Your MariaDB connection id is 17
Server version: 10.2.31-MariaDB MariaDB Server

Copyright (c) 2000, 2018, Oracle, MariaDB Corporation Ab and others.

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

MariaDB [(none)]> SELECT now();
+---------------------+
| now()               |
+---------------------+
| 2020-04-22 11:19:38 |
+---------------------+
1 row in set (0.01 sec)
like image 23
Dung Avatar answered Sep 23 '22 17:09

Dung