[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原樣存儲html

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;

超過存儲範圍的時候sql

相關文章
相關標籤/搜索