MySQL 8.0.12 时区设置和修改


1.查询系统支持当前的时区设置:
mysql> select version();
+-----------+
| version() |
+-----------+
| 8.0.12    |
+-----------+
1 row in set (0.00 sec)
mysql> show variables like '%time_zone%';
+------------------+--------+
| Variable_name    | Value  |
+------------------+--------+
| system_time_zone | CST    |
| time_zone        | SYSTEM |
+------------------+--------+
2 rows in set (0.00 sec)
 
2.修改时区设置:
方法1:写入到配置文件需要重启mysql实例:
[mysqld] 
default-time-zone=timezone
修改为
default-time-zone = '+8:00'
 
 
方法2:在线修改和查看:
 
mysql> set time_zone='+8:00';
Query OK, 0 rows affected (0.00 sec)
 
mysql> show variables like '%time_zone%';
+------------------+--------+
| Variable_name    | Value  |
+------------------+--------+
| system_time_zone | CST    |
| time_zone        | +08:00 |
+------------------+--------+
2 rows in set (0.01 sec)
 
--通过now() 查看:
mysql> show variables like '%time_zone%';
+------------------+--------+
| Variable_name    | Value  |
+------------------+--------+
| system_time_zone | CST    |
| time_zone        | +08:00 |
+------------------+--------+
2 rows in set (0.01 sec)
 
mysql> select now();
+---------------------+
| now()               |
+---------------------+
| 2018-08-28 16:08:38 |
+---------------------+
1 row in set (0.00 sec)
 
mysql> set time_zone='+0:00';
Query OK, 0 rows affected (0.00 sec)
 
mysql> show variables like '%time_zone%';
+------------------+--------+
| Variable_name    | Value  |
+------------------+--------+
| system_time_zone | CST    |
| time_zone        | +00:00 |
+------------------+--------+
2 rows in set (0.01 sec)
 
mysql> select now();
+---------------------+
| now()               |
+---------------------+
| 2018-08-28 08:09:12 |
+---------------------+
1 row in set (0.00 sec)
 
--自MySQL 8.0 GA版本开始支持将参数写入并且持久化:
mysql> set persist time_zone='+0:00';
 
--针对application 可以设置:
jdbc:mysql://localhost:3306/database?useUnicode=true&characterEncoding=UTF-8&useOldAliasMetadataBehavior=true&autoReconnect=true&serverTimezone=UTC 
 
--结论:
 mysql> set time_zone='+8:00'; 和time_zone='system'是等同的,默认为系统时间。

  • 1
    点赞
  • 0
    评论
  • 0
    收藏
  • 一键三连
    一键三连
  • 扫一扫,分享海报

相关推荐
©️2020 CSDN 皮肤主题: 黑客帝国 设计师:白松林 返回首页
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、C币套餐、付费专栏及课程。

余额充值