当前位置: 移动技术网 > IT编程>数据库>Mysql > [MySQL] timestamp和datetime的区别和大坑

[MySQL] timestamp和datetime的区别和大坑

2019年03月26日  | 移动技术网IT编程  | 我要评论

1.timestamp占用4个字节;datetime占用8个字节
2.timestamp范围1970-01-01 00:00:01.000000 到 2038-01-19 03:14:07.999999;datetime是1000-01-01 00:00:00.000000 到 9999-12-31 23:59:59.999999
3.timestamp默认支持not null default current_timestamp自动更新当前时间;datetime 在5.6版本后才支持,需要手动指定not null default current_timestamp
4.timestamp转成utc存储,查询再自动转回来;datetime原样存储

create table strong_passwd_whitelist( 
id int unsigned not null auto_increment, 
email_id int unsigned not null default 0, 
update_date timestamp,
create_date datetime not null default current_timestamp, 
primary key(id), 
key index_email_id(email_id) 
) engine=innodb charset=utf8;

超过存储范围的时候

 

 

  

如对本文有疑问, 点击进行留言回复!!

相关文章:

验证码:
移动技术网