How do I set the time zone of MySQL?

后端 未结 20 3282
闹比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:31

    First to figure out what the time_zone is you can query

    SHOW VARIABLES LIKE '%time_zone%'; 
    

    Your output should be something similar as follows

    **Variable_name**     **Value**
    system_time_zone      CDT
    time_zone             SYSTEM
    

    Then if you want to confirm that you are in say some time zone like CDT instead of something like EST you can check what time it thinks your machine is in by saying

    SELECT NOW();
    

    If this is not the time you want you need to change it... all you need to do is SET time_zone = timezone_name. Make sure it is one that is in Continent/City format.

    If you are on a shared server because you have a hosting service please refer to these answers regarding changing the php.ini file or the .htaccess file.

提交回复
热议问题