Mysql--13 索引

1.索引:提高获取数据速度

  

索引分类:
    1.主键索引:primary key 唯一,主键唯一,一个表只能有一个列作为主键。
    
    2.唯一索引:unique key  可以标注多列为唯一索引,
    
    3.常规索引:(key /index)key 索引名(字段名)
    
    4.全文索引:    fulltext index  索引名(字段名)  快速定位数据
 

===========================
查看表的索引:
show index from user;
增加全文索引:
alter  table 表名  add  fulltext index  `索引名`( `字段`);

======分析sql语句=======
explain  select * from user;---非全文索引;
explain select * from match(字段名) against('fds');

  

创建索引方式:
    1.创建表的时候,创建索引:
        create table `表名`(
        `id` int(2) unsigned not null  auto_increment ,
        `name` varchar(20) not null,
        `sex` varchar(2) not null,
        `address` varchar(50) not null,
        `email` varchar(30) not null,
        `birthday` datetime not null,
           primary key (`id`),
         unique key `unique_index`(`name`),
         key  `key_index`(`sex`)
        )engine=innodb default charset=utf8mb4;
    2.修改表结构时,创建索引
        alter table  表名   add   fulltext index `索引名`(`address`);
    3.索引语法:
    create index  索引名  on 表名(`字段名`);

  

猜你喜欢

转载自www.cnblogs.com/chencn/p/12304262.html