Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit d74da06

Browse files
数据库结构优化
1 parent bf89d44 commit d74da06

File tree

1 file changed

+18
-0
lines changed

1 file changed

+18
-0
lines changed
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
选择合适的数据类型
2+
1.使用可存下数据的最小的数据类型
3+
2.使用简单地数据类型,Int要比varchar类型在mysql处理上更简单
4+
3.尽可能使用not null定义字段,这是由innodb的特性决定的,
5+
因为非not null的数据可能需要一些额外的字段进行存储,这样就会增加一些IO。
6+
可以对非null的字段设置一个默认值
7+
4.尽量少用text,非用不可最好分表,
8+
将text字段存放到另一张表中,在需要的时候再使用联合查询,这样可提高查询主表的效率
9+
例子1、用Int存储日期时间
10+
from_unixtime()可将Int类型的时间戳转换为时间格式
11+
select from_unixtime(1392178320); 输出为 2014年02月12日 12:12:00
12+
unix_timestamp()可将时间格式转换为Int类型
13+
select unix_timestamp('2014年02月12日 12:12:00'); 输出为1392178320
14+
例子2
15+
存储IP地址——bigInt
16+
利用inet_aton(),inet_ntoa()转换
17+
select inet_aton('192.169.1.1'); 输出为3232301313
18+
select inet_ntoa(3232301313); 输出为192.169.1.1

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /