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

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;

超过存储范围的时候

  

原文地址:https://www.cnblogs.com/taoshihan/p/10594884.html