Memory存储引擎可以选择Hash或BTree索引,Hash索引只能用于=或<=>的等式比较。
1、普通索引:create index on Tablename(列的列表)
alter table TableName add index (列的列表)
create table TableName([…], index [IndexName] (列的列表)
2、唯一性索引:create unique index
alter … add unique
主键:一种唯一性索引,必须指定为primary key
3、全文索引:从3.23.23版开始支持全文索引和全文检索,FULLTEXT,
可以在char、varchar或text类型的列上创建。
4、单列索引、多列索引:
多个单列索引与单个多列索引的查询效果不同,因为:
执行查询时,MySQL只能使用一个索引,会从多个索引中选择一个限制最为严格的索引。
5、最左前缀(Leftmost Prefixing):多列索引,例如:fname_lname_age索引,以下的搜索条件MySQL都将使用
fname_lname_age索引:firstname,lastname,age;firstname,lastname;firstname,其他情况将不使用。