MySQL時區修改
阿新 • • 發佈:2019-01-26
環境介紹:
OS版本:RHEL5.5
MySQL版本:5.5.40
參考連結:http://dev.mysql.com/doc/refman/5.5/en/time-zone-leap-seconds.html
有一個需求:一個考勤系統,多個AP分佈在全球,時間必須以+8時區來計算,那必須修改MySQL伺服器時間來決定!
檢視mysql server當前時區
mysql> show variables like '%time_zone%';
+------------------+--------+
| Variable_name | Value |
+------------------+--------+
| system_time_zone | CST |
| time_zone | SYSTEM |
+------------------+--------+
2 rows in set (0.00 sec)
修改辦法:
方法1:修改my.cnf
[mysqld]
default-time-zone='+8:00'
儲存,退出
重啟mysql 伺服器
方法2:修改引數
mysql> set time_zone = '+8:00';
驗證:
mysql> show variables like '%time_zone%';
+------------------+--------+
| Variable_name | Value |
+------------------+--------+
| system_time_zone | CST |
| time_zone | +08:00 |
+------------------+--------+
2 rows in set (0.00 sec)
mysql> select now();
+---------------------+
| now() |
+---------------------+
| 2011-18-21 18:39:07 |
+---------------------+
1 row in set (0.00 sec)
OS版本:RHEL5.5
MySQL版本:5.5.40
參考連結:http://dev.mysql.com/doc/refman/5.5/en/time-zone-leap-seconds.html
有一個需求:一個考勤系統,多個AP分佈在全球,時間必須以+8時區來計算,那必須修改MySQL伺服器時間來決定!
檢視mysql server當前時區
mysql> show variables like '%time_zone%';
+------------------+--------+
| Variable_name | Value |
+------------------+--------+
| system_time_zone | CST |
| time_zone | SYSTEM |
+------------------+--------+
2 rows in set (0.00 sec)
修改辦法:
方法1:修改my.cnf
[mysqld]
default-time-zone='+8:00'
儲存,退出
重啟mysql 伺服器
方法2:修改引數
mysql> set time_zone = '+8:00';
驗證:
mysql> show variables like '%time_zone%';
+------------------+--------+
| Variable_name | Value |
+------------------+--------+
| system_time_zone | CST |
| time_zone | +08:00 |
+------------------+--------+
2 rows in set (0.00 sec)
mysql> select now();
+---------------------+
| now() |
+---------------------+
| 2011-18-21 18:39:07 |
+---------------------+
1 row in set (0.00 sec)