How to set up mysql session at a specific time zone?

I need to dynamically change the time zone for mysql sessions due to going through multiple databases that have different time zones.

How to configure mysql on tiemzone for all queries related to mysql date?

+4
source share
1 answer

You can use SET TIME_ZONE to set the session to a specific UTC offset.

For example, I am in UTC -05: 00, but I can switch to UTC as follows:

 mysql> select now(); +---------------------+ | now() | +---------------------+ | 2011-03-02 12:32:39 | +---------------------+ 1 row in set (0.00 sec) mysql> set time_zone = '+00:00'; Query OK, 0 rows affected (0.00 sec) mysql> select now(); +---------------------+ | now() | +---------------------+ | 2011-03-02 17:32:45 | +---------------------+ 1 row in set (0.00 sec) 
+7
source

Source: https://habr.com/ru/post/1342024/


All Articles