您的位置:首页 > 数据库 > MySQL

MySQL:给表建立索引及索引的显示

2013-10-14 14:38 357 查看
建表:
create table user(

id int not null primary key,

username varchar(15) not null,

passward varchar(20) not null,

nickname varchar(15) not null,

mail varchar(30) not null,

self_intro varchar(70) not null,

userPhoto varchar(100) not null,

photo_add varchar(100) not null,

friends_id varchar(500) not null

)engine = MyISAM default charset = utf8;

engine = MyISAM :指定MySQL中此表使用的数据库引擎为MyISAM
default charset = utf8: 制定此表的文字编码为utf8

建立索引:
create index user_username on user(username);
alter table user add unique (username);

建立唯一性索引

create unique index user_username on user(username);

删除索引
alter table user drop index user_username;
drop index user_username on user;

==================================================

mysql> show index from user;



· Table

表的名称。

· Non_unique

如果MySQL索引不能包括重复词,则为0。如果可以,则为1。

· Key_name

索引的名称。

· Seq_in_index

索引中的列序列号,从1开始。

· Column_name

列名称。

· Collation

列以什么方式存储在索引中。在MySQL中,有值‘A’(升序)或NULL(无分类)。

· Cardinality

MySQL索引中唯一值的数目的估计值。通过运行ANALYZE TABLE或myisamchk -a可以更新。基数根据被存储为整数的统计数据来计数,所以即使对于小型表,该值也没有必要是精确的。基数越大,当进行联合时,MySQL使用该索引的机会就越大。

· Sub_part

如果列只是被部分地编入索引,则为被编入索引的字符的数目。如果整列被编入索引,则为NULL。

· Packed

指示关键字如何被压缩。如果没有被压缩,则为NULL。

· Null

如果列含有NULL,则含有YES。如果没有,则该列含有NO。

· Index_type

用过的索引方法(BTREE,
FULLTEXT, HASH, RTREE)。

· Comment
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: