Changing the connection timezone in MySQL

前端 未结 6 633
情话喂你
情话喂你 2020-12-28 14:07

My server is running in MDT

So I used following one to convert EST

SET  time_zone = \'-5:00\'

But, how c

相关标签:
6条回答
  • 2020-12-28 14:40

    Have you tried using a zoneinfo name such as "America/New_York" instead of the abbreviation (which is only valid for half the time)?

    Ideally, you shouldn't use the server time zone at all of course - store dates in UTC and then convert it to the appropriate time zone in the client code. (This does depend on what you're storing, mind you. Future date/time values specified by a user with a time zone should be stored that way, not converted to any other time zone, in case the rules change between now and the future date/time. But for instants in time recorded by machines, e.g. for logging, transactions etc, I'd definitely store UTC. I would never suggest storing "just the local time and assume that the server and the client have the same rules".)

    0 讨论(0)
  • 2020-12-28 14:44

    Since you're using Windows, your going to have to import the time zone description tables to your MySQL server.

    http://dev.mysql.com/downloads/timezones.html

    0 讨论(0)
  • 2020-12-28 14:48

    Just for the sake of completeness, Mac users can find mysql_tzinfo_to_sql utility in /usr/local/mysql/bin directory.

    Hence the complete command will be /usr/local/mysql/bin/mysql_tzinfo_to_sql /usr/share/zoneinfo | ./mysql -p -u root mysql

    I spent hours to find the utility, the above path may save yours!

    0 讨论(0)
  • 2020-12-28 14:50

    For me on Windows using WampServer:

    • download the POSIX version from https://dev.mysql.com/downloads/timezones.html
    • unzip it
    • put all files in wamp mysql data: C:\wamp\bin\mysql\mysql5.7.11\data\mysql
    • restart wamp

    More Info:

    “To use a time zone package that contains .frm, .MYD, and .MYI files for the MyISAM time zone tables, download and unpack it. These table files are part of the mysql database, so you should place the files in the mysqlsubdirectory of your MySQL server's data directory. Stop the server before doing this and restart it afterward”

    http://dev.mysql.com/doc/refman/5.7/en/time-zone-support.html#time-zone-installation

    0 讨论(0)
  • 2020-12-28 15:00

    For Linux, BSD, and Mac OS X if you need to load the timezone table do this:

    $ mysql_tzinfo_to_sql /usr/share/zoneinfo | mysql -uroot mysql
    
    0 讨论(0)
  • 2020-12-28 15:06

    In case of Mysql8 and want to set EDT timezone 'America/New_York' then follow the below steps:

    1. Go to the /etc/my.cnf
    2. Add this under [mysqld] default-time-zone='America/New_York'
    3. systemctl restart mysqld

    If you face the issue realted fatal error like this:

    Fatal error: Illegal or unknown default time zone
    

    Then do the following steps:

    1. first remove the entry from /etc/my.cnf file for default-time-zone='America/New_York'

    2. Go to shell(exit from mysql) and run the command

      $ mysql_tzinfo_to_sql /usr/share/zoneinfo | mysql -u root -p mysql
      
    3. Add the line again

    4. Restart mysql

    0 讨论(0)
提交回复
热议问题