美文网首页mysql
MySQL中数据类型timestamp大坑

MySQL中数据类型timestamp大坑

作者: HachiLin | 来源:发表于2022-12-28 10:47 被阅读0次

1. 日期字段定义

  • 定义1
`last_login_time` timestamp NULL DEFAULT NULL COMMENT '上次登录时间'
  • 定义2
`last_login_time` datetime NULL DEFAULT NULL COMMENT '上次登录时间'

2. timestamp日期范围坑

如果我们存储的日期需要未来一个很长的跨度,那么使用timestamp插入或更新数据时就会报如下错误:

错误截图

通过搜索得知:timestamp所能存储的时间范围为:'1970-01-01 00:00:01.000000' 到 '2038-01-19 03:14:07.999999'。并且受时区影响。

具体原因参考mysql官方文档:https://dev.mysql.com/doc/refman/8.0/en/datetime.html

3. 解决方案

alter table XXX modify column `last_login_time` datetime NULL DEFAULT NULL COMMENT '上次登录时间'

4. 参考文章

相关文章

网友评论

    本文标题:MySQL中数据类型timestamp大坑

    本文链接:https://www.haomeiwen.com/subject/axzaqdtx.html