mysql数据库增加索引

alter table 表名 add primary key (id);   //主键索引

alter table 表名 add unique key [索引名称]  (字段); // 唯一索引

alter table 表名 add key  [索引名称]  (字段); // 普通索引

alter table 表名 add fulltext key  [索引名称]  (字段); //全文索引

① 主键索引(值不重复,auto_increment自增特性,id)

② 唯一索引(字段内容不能重复)

③ 普通索引

④ 全文索引(把一个文章的内容都给创建索引)

例子:给students 表增加唯一索引name  

alter table students add unique key (name);

删除非主键索引

<!--删除students中的age字段的普通索引-->
alter table students drop key age;
执行计划explain

explain  sql语句G;

做执行计划的目的,就使得sql语句的运行要关联使用索引,就看”key”的标志
原文地址:https://www.cnblogs.com/kevin-yang123/p/14078186.html