How do I install the time zone in MySQL

Compare - How do I get the current time zone from MySQL?

From the manual (section 9.6):

The current values ​​of the global and customer-specific time zones can be called up as follows:

To edit The above works when MySQL is slave to the system's time zone, which is less than helpful. Since you are working in PHP and the answer is MySQL, you can ask the system what time zone it above . (Of course, as VolkerK said, PHP could be running on a different server, but as the assumptions go, assuming the web server and the DB server it is referring to are on [if not actually] discontinued huge Jump.) But be careful (as with MySQL), you can change the time zone that PHP uses (), which means that it can use a different value than the operating system. Once you have mastered the PHP code, you should know if you are doing this and are okay.

But the whole question of which time zone the MySQL server is using can be a tangent, because if you ask the server what time zone it is in, you can find out absolutely nothing about the data in the database. Read on for details:

Further discussion :

Of course, if you are in control of the server, you can make sure that the time zone is a known quantity. If you don't have control of the server, you can use the one from your connection Set the time zone used as follows:

This sets the time zone to GMT, so all further operations (like) use GMT.

Note, however, that time and date values Not with time zone information stored in MySQL:

Knowing the server's time zone is therefore only important in relation to functions that are currently getting the time, such as,, etc.; You do not know which time zone the data in the database data is using. You could assume that they were written with the server's time zone, but this assumption may be incorrect. To know the time zone of any dates or times stored in the data, you need to make sure they are stored with time zone information or (like me) make sure they are always in GMT.

Why is it assumed that the data was written incorrectly using the server's time zone? Well, for one thing, the data may have been written over a connection that set a different time zone. The database may have been moved from one server to another where the servers were in different time zones (I learned this when I inherited a database that moved from Texas to California). But even if the data is written on the server with the current time zone, it is still ambiguous. Last year, daylight saving time was turned off in the United States on November 1 at 2:00 a.m. For example, suppose my server is in California using the Pacific time zone and I have the value in the database. When was it? Was that 1.30am on November 1st PDT or 1.30am on November 1st PST (an hour later)? You have absolutely no way of knowing. Moral: Always save the data in GMT (without daylight saving time) and convert it to the desired time zone if necessary.