修改MySQL默认时区

修改MySQL默认时区

1. 修改为东八区

默认数据库时区比服务器少8小时

登录到 mysql -uroot -p

查看数据库时间 select now();

查询数据库时区 show variables like '%time_zone%';

修改时区 set global time_zone = '+8:00'; set time_zone = '+8:00';

刷新 flush privileges;

重新查询时区 show variables like '%time_zone%';

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
$ mysql -uroot -p
Enter password:
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 8
Server version: 8.0.17 MySQL Community Server - GPL

Copyright (c) 2000, 2019, Oracle and/or its affiliates. All rights reserved.

Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

mysql>
mysql> select now();
+---------------------+
| now() |
+---------------------+
| 2019-12-07 05:17:36 |
+---------------------+
1 row in set (0.00 sec)

mysql>
mysql> show variables like '%time_zone%';
+------------------+--------+
| Variable_name | Value |
+------------------+--------+
| system_time_zone | CST |
| time_zone | SYSTEM |
+------------------+--------+
2 rows in set (0.04 sec)

mysql>
mysql> set global time_zone = '+8:00';
Query OK, 0 rows affected (0.01 sec)

mysql> set time_zone = '+8:00';
Query OK, 0 rows affected (0.00 sec)

mysql>
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>
mysql> flush privileges;
Query OK, 0 rows affected (0.01 sec)

mysql>
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>

2. 修改配置文件

打开mysql的配置文件 添加default-time_zone = '+8:00'

重启mysql

本文结束  感谢您的阅读
  • 本文作者: Wang Ting
  • 本文链接: /zh-CN/2019/12/07/修改MySQL默认时区/
  • 发布时间: 2019-12-07 05:26
  • 更新时间: 2022-10-24 22:45
  • 版权声明: 本博客所有文章除特别声明外,均采用 BY-NC-SA 许可协议。转载请注明出处!