1.使用可以存下你的数据的最小的数据类型
2.使用简单的数据类型。int 要比varchar类型在mysql处理上简单
3.尽可能的使用not null定义字段
4.尽量少用text类型,费用不可时最好考虑分表
例如:
1.用int来存储日期时间,通过FROM_UNIXTIME(),UNIX_TIMESTAMP()来相互转化
1
2
3
4
5
6
7create table test(
id int auto_increment not null,
timestr int,
primary key(id)
);
insert into test(timestr) values(UNIX_TIMESTAMP('2015-01-01 11:10:09'));
select FROM_UNIXTIME(timestr) FROM test;