How do I set the time zone of MySQL?

后端 未结 20 3661
闹比i
闹比i 2020-11-21 07:07

On one server, when I run:

mysql> select now();
+---------------------+
| now()               |
+---------------------+
| 2009-05-30 16:54:29 |
+---------         


        
20条回答
  •  星月不相逢
    2020-11-21 07:30

    To set the standard time zone at MariaDB you have to go to the 50-server.cnf file.

    sudo nano /etc/mysql/mariadb.conf.d/50-server.cnf
    

    Then you can enter the following entry in the mysqld section.

    default-time-zone='+01:00'
    

    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]
    
    # this is only for the mysqld standalone daemon
    [mysqld]
    
    #
    # * Basic Settings
    #
    user            = mysql
    pid-file        = /var/run/mysqld/mysqld.pid
    socket          = /var/run/mysqld/mysqld.sock
    port            = 3306
    basedir         = /usr
    datadir         = /var/lib/mysql
    tmpdir          = /tmp
    lc-messages-dir = /usr/share/mysql
    skip-external-locking
    
    ### Default timezone ###
    default-time-zone='+01:00'
    
    # Instead of skip-networking the default is now to listen only on
    # localhost which is more compatible and is not less secure.
    

    The change must be made via the configuration file, otherwise the MariaDB server will reset the mysql tables after a restart!

提交回复
热议问题