mysql索引创建 删除 查看 检测

        小编今天稍微学习了下mysql 索引的相关知识 

1> 创建索引

    altert table 表名 add unique(列);           //创建唯一索引

    altert table 表名 add index  索引名(列);  //创建普通索引

    altert table 表名 add primary key(列);   //创建主键索引

    alter  table  表名 add fulltext(列1,列2);  //创建全文索引

    create index 索引名 on  表名(列);      

    create unique index 索引名 on 表名(列);   

create 不能创建primary key 索引

2> 删除索引

    Drop index 索引名 on 表名

    alter table 表名 drop index 索引名

    alter table 表名 drop primary key

3> 查看索引

    show index from 表名

    show keys from 表名

4> 检测索引

 explain select * from news where news_id=7

下面是查询的效果 

5> index,primary key,unique,fulltext 区别

PRIMARY     主键,一个表中只能有一个主键,  该键值不能为   NULL   ,不能重复 

UNIQUE     唯一键(或称   第二辅助键),一个表中可以有多个 该键值不能重复,但是可以有多个记录值为   NULL 

INDEX        普通的索引 

FULLTEXT    全文索引

 先说到这里啊 。。还有后续内容

 

原文地址:https://www.cnblogs.com/wlgaojin/p/2740497.html