1、查看当前时间

> select curtime(); #或select now()也可以
+-----------+
| curtime() |
+-----------+
| 15:18:10 |
+-----------+

> show variables like "%time_zone%";
+------------------+--------+
| Variable_name | Value |
+------------------+--------+
| system_time_zone | CST |
| time_zone | SYSTEM |
+------------------+--------+

#time_zone说明mysql使用system的时区,system_time_zone说明system使用CST时区

2、修改时区 通过sql修改

> set global time_zone = '+8:00'; ##修改mysql全局时区为北京时间,即我们所在的东8区
> set time_zone = '+8:00'; ##修改当前会话时区
> flush privileges; #立即生效

3、修改时区 通过配置文件

# vim /etc/my.cnf ##在[mysqld]区域中加上
default-time_zone = '+8:00'

# /etc/init.d/mysqld restart ##重启mysql使新时区生效

 

相关文章:

  • 2022-12-23
  • 2021-08-18
  • 2022-02-04
  • 2022-12-23
  • 2022-12-23
  • 2021-06-28
  • 2022-01-21
猜你喜欢
  • 2022-12-23
  • 2021-12-09
  • 2022-02-12
  • 2021-12-19
相关资源
相似解决方案