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
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
相关文章推荐
- 给MySQL增加一个表示例
- MYSQL–my.cnf配置中文详解
- 给MySQL中某表增加一个新字段,设为主键值为自动增长。
- MYSQL–my.cnf配置中文详解
- MYSQL启用日志,和查看日志
- MySQL导入.sql文件及常用命令
- MySQL常见的错误及解决方法
- mysql常用命令
- 101 个 MySQL 的调节和优化的提示
- 如何平滑“重启“”mysql
- 查看mysql数据库表上的重复索引列
- 在Linu型环境下面安装MySQL指导
- 修复表小计
- mysql 建表
- MySQL存储过程
- MySQL实时在线备份恢复方案:Replication+LVM Snapsho
- Mysql创建、删除用户、查询所有用户等教程,提升您的MYSQL安全度!
- 从mysql表中随机取出几行数据
- mysql执行*.sql文件命令
- mysql中对数据库的每个表执行优化的存储过程