索引


使用索引可以加快查询速度

索引的原则

 数据量很大,且经常被查询的数据表可以设置索引

 索引只添加在经常被作为检索条件的字段上面

 不要在大字段上创建索引,字符串过长不适合添加索引

use test;
#创建索引
create table t_message (
 id int unsigned primary key,
 content varchar(200) not null,
 type ENUM("公告","通报","个人通知") not null,
 create_time timestamp not null,
 index idx_type (type)
)character set = utf8;
#删除索引
drop index idx_type on t_message;
#添加索引
create index idx_type on t_message(type);
alter table t_message add index idx_type(type);
#查看索引信息
show index from t_message;