第一步,创建一个表,结构如下:create table t (id int unsigned not null,name varchar(20) not null default ‘-‘);
第二步,添加索引,二索引有分为几类,普通索引,主键索引,和唯一索引,如图就是步骤:图中数123就是对应普通索引,主键索引,和唯一索引
alter table 表名 add index/unique/primary key (索引名);
第三步,表里面已经有索引了,要怎么查看呢?用这两个命令:show index from table;或show keys from table;如图:
show index from 表名;
show keys from 表名;
第四步,有时候索引太多,会引起增删改查的性能,所以可以创建就可以删除,命令如下:
drop index 索引名 on 表名;
DROP INDEX index_name ON talbe_name;
ALTER TABLE table_name DROP INDEX index_name;
ALTER TABLE table_name DROP PRIMARY KEY;