Mac MySQL modifies the default time zone to UTC

Time:2022-1-14

If your time zone setting is+08:00The explanation is Beijing time, but all our online servers are UTC time. This difference will bring some unexpected results. Let’s uniformly set the UTC time zone!

MySQL [email protected](none):(none)> show variables like'%time_zone';
+------------------+--------+
| Variable_name    | Value  |
+------------------+--------+
| system_time_zone | CST    |
| time_zone        | +08:00 |
+------------------+--------+
2 rows in set
Time: 0.025s

Step 1:

edit/etc/my.cnffile

cd /etc
sudo vim my.cnf

Step 2:

Enter the following

[mysqld]
default-time-zone='+08:00'  

Save exit

Step 3:

restartmysql server

Step 4:

Sign inmysql server, if so, it will take effect

MySQL [email protected](none):(none)> show variables like'%time_zone';
+------------------+--------+
| Variable_name    | Value  |
+------------------+--------+
| system_time_zone | CST    |
| time_zone        | +00:00 |
+------------------+--------+
2 rows in set
Time: 0.025s