Definition:An index is a single, physical storage structure that sorts the values of one or more columns in a database table#为字段创建索引
#在表中的字段中创建索引
Mysql> Create IndexInd_score onscore (name); Query OK,0Rows Affected (0.03sec) Records:0Duplicates:0Warnings:0#查看索引mysql>ShowIndex fromscore;+-------+------------+-----------+--------------+-------------+-----------+-------------+----------+--------+ ------+------------+---------+---------------+| Table |Non_unique|Key_name|Seq_in_index|column_name|Collation|Cardinality|Sub_part|Packed| Null |Index_type|Comment|Index_comment|+-------+------------+-----------+--------------+-------------+-----------+-------------+----------+--------+- -----+------------+---------+---------------+|Score| 0 | PRIMARY | 1 |Id|A| 4 | NULL | NULL | |BTREE| | ||Score| 1 |Ind_score| 1 |Name|A| 4 | NULL | NULL | |BTREE| | |+-------+------------+-----------+--------------+-------------+-----------+-------------+----------+--------+- -----+------------+---------+---------------+2Rowsinch Set(0.00Sec
#也可以在创建表的时候创建索引
#删除索引
MySQL>dropindexon0 rows affected (0.01 0 0 0
#用alter创建/Delete Index
Mysql> Alter TableScoreAdd IndexInd_score (name); Query OK,0Rows Affected (0.02sec) Records:0Duplicates:0Warnings:0MySQL> Alter TableScoreDrop IndexInd_score; Query OK,0Rows Affected (0.01sec) Records:0Duplicates:0Warnings:0
#创建索引值唯一的索引 (the benefit is that data can be quickly queried by a unique index when there is a large number)
MySQL>Createuniqueindexon0 rows affected ( 0.020 0 0
Cheng Plan--mysql Index