查询索引
1 | SHOW {INDEX | INDEXES | KEYS} |
例子:1
2SHOW INDEX FROM mydb.mytable;
show index from authority;
字段较多时,竖着看更清晰1
SHOW INDEX FROM mydb.mytable\G;
创建索引
直通车:https://dev.mysql.com/doc/refman/5.7/en/create-index.html1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23CREATE [UNIQUE | FULLTEXT | SPATIAL] INDEX index_name
[index_type]
ON tbl_name (key_part,...)
[index_option]
[algorithm_option | lock_option] ...
key_part:
col_name [(length)] [ASC | DESC]
index_option:
KEY_BLOCK_SIZE [=] value
| index_type
| WITH PARSER parser_name
| COMMENT 'string'
index_type:
USING {BTREE | HASH}
algorithm_option:
ALGORITHM [=] {DEFAULT | INPLACE | COPY}
lock_option:
LOCK [=] {DEFAULT | NONE | SHARED | EXCLUSIVE}
例子:1
CREATE INDEX id_index ON lookup (id) USING BTREE;
删除索引
语法使用的alert,比较复杂,这儿只放一个链接
https://dev.mysql.com/doc/refman/5.7/en/alter-table.html
例子:1
alter table authority drop index UQE_authority_page;
联合索引
联合索引又叫复合索引。对于复合索引:Mysql从左到右的使用索引中的字段,一个查询可以只使用索引中的一部份,但只能是最左侧部分。例如索引是key index (a,b,c). 可以支持a | a,b| a,b,c 3种组合进行查找,但不支持 b,c进行查找 .当最左侧字段是常量引用时,索引就十分有效。
例子:1
2
3show index from authority;
alter table authority drop index UQE_authority_page;
CREATE index UQE_authority_page on authority(company_id,page);