• ADADADADAD

    【Mysql】修改mysql时区[ mysql数据库 ]

    mysql数据库 时间:2024-12-03 12:15:03

    作者:文/会员上传

    简介:

    首先需要查看mysql的当前时区,用time_zone参数mysql> show global variables like '%zone%';+------------------+--------+| Variable_name| Value |+------------

    以下为本文的正文内容,内容仅供参考!本站为公益性网站,复制本文以及下载DOC文档全部免费。

    首先需要查看mysql的当前时区,用time_zone参数

    mysql> show global variables like '%zone%';

    +------------------+--------+

    | Variable_name| Value |

    +------------------+--------+

    | system_time_zone | CST| ---系统时间,北京时间

    | time_zone| SYSTEM | ----mysql所用的时区,这里是调用系统时区,也就是北京时间

    +------------------+--------+

    2 rows in set (0.17 sec)


    验证下:

    mysql> select now();

    +---------------------+

    | now() |

    +---------------------+

    | 2018-11-30 17:11:55 |

    +---------------------+

    1 row in set (0.18 sec)

    修改为utc时区

    mysql> set time_zone='+0:00';

    mysql> select now();

    +---------------------+

    | now() |

    +---------------------+

    | 2018-11-30 09:12:06 |

    +---------------------+

    1 row in set (0.18 sec)

    修改为东八区

    mysql> set time_zone='+8:00';

    Query OK, 0 rows affected (0.24 sec)

    mysql> select now();

    +---------------------+

    | now() |

    +---------------------+

    | 2018-11-30 17:21:40 |

    +---------------------+

    1 row in set (0.72 sec)

    永久修改可以通过修改my.cnf

    在 [mysqld] 之下加

    default-time-zone=timezone

    来修改时区。如:

    default-time-zone = '+8:00'

    修改完了记得记得重启msyql

    注意一定要在 [mysqld] 之下加 ,否则会出现 unknown variable 'default-time-zone=+8:00'

    注意:时区这个对timestamp类型的才有影响,datetime 是没影响的,如:

    mysql> select * from uc_smallfeature_sharerecords(时间戳是timestamp类型);

    +------+---------------------+-------------+----------+--------+----------+

    | id | create_time| destination | platform | userid | username |

    +------+---------------------+-------------+----------+--------+----------+

    | 3425 | 2018-12-25 19:42:51 | 123213 | 123 | 123| 123 |

    +------+---------------------+-------------+----------+--------+----------+

    mysql> select * from uc_push_token(时间戳是datetime类型);

    +---------+-----------+-------+---------------------+---------------------+

    | user_id | push_type | token | create_time| update_time|

    +---------+-----------+-------+---------------------+---------------------+

    | 1 |0 | | 2018-12-25 19:40:49 | 2018-12-25 19:40:49 |

    +---------+-----------+-------+---------------------+---------------------+

    mysql> show global variables like '%zone%';

    +------------------+--------+

    | Variable_name| Value |

    +------------------+--------+

    | system_time_zone | UTC|

    | time_zone| +08:00 |

    +------------------+--------+

    2 rows in set (0.00 sec)

    mysql> set global time_zone='+0:00';

    Query OK, 0 rows affected (0.00 sec)

    重连查询:

    mysql> select * from uc_smallfeature_sharerecords;(timestamp类型的变了)

    +------+---------------------+-------------+----------+--------+----------+

    | id | create_time| destination | platform | userid | username |

    +------+---------------------+-------------+----------+--------+----------+

    | 3425 | 2018-12-25 11:42:51 | 123213 | 123 | 123| 123 |

    +------+---------------------+-------------+----------+--------+----------+

    1 row in set (0.00 sec)

    mysql> select * from uc_push_token;(datetime类型的不会变)

    +---------+-----------+-------+---------------------+---------------------+

    | user_id | push_type | token | create_time| update_time|

    +---------+-----------+-------+---------------------+---------------------+

    | 1 |0 | | 2018-12-25 19:40:49 | 2018-12-25 19:40:49 |

    +---------+-----------+-------+---------------------+---------------------+

    【Mysql】修改mysql时区.docx

    将本文的Word文档下载到电脑

    推荐度:

    下载
    热门标签: mysql修改