认识索引
存储结构
查看文件路径
show variables like ‘datadir’;
InnoDB:frm(表结构)、ibd(索引和数据)
MyISAM:frm(表结构)、MYI(索引)、MYD(数据)
InnoDB结构
MyISAM结构
使用索引
--创建普通索引
create table score(
id int(11) auto_increment primary key,
name varchar(50) not null,
math int(5) not null,
index(字段)
);
--创建唯一索引
create table score(
id int(11) auto_increment primary key,
name varchar(50) not null,
math int(5) not null,
unique index 索引名(字段)
);
--创建全文索引
create table score(
id int(11) auto_increment primary key,
name varchar(50) not null,
math int(5) not null,
fulltext key 索引名(字段)
);
--查询全文索引内容
select * from fulltext_table
where match(fulltext_col)
against('字符串' in natural language mode);
--创建单列索引
create table score(
id int(11) auto_increment primary key,
name varchar(50) not null,
math int(5) not null,
index 索引名(字段(索引长度))
);
--创建多列索引
create table score(
id int(11) auto_increment primary key,
name varchar(50) not null,
math int(5) not null,
index 索引名(字段1,字段2)
);
--创建空间索引
create table score(
id int(11) auto_increment primary key,
name varchar(50) not null,
math int(5) not null,
spatial index 索引名(字段)
);
--创建索引
create [unique][fulltext][spatial]index 索引名 on 表名(字段);
--删除索引
drop index 索引名 on 表名;
索引失效
使用分析工具
失效类型
- 联合索引最右匹配