mysql Index
创建索引
方法1
create table 表(
col1 int,
col2 int,
…
index | key index_name (列名)方法2
alter table 表名 ADD index
alter table student_table add index index_name(stu_id);方法3
create index index_name on 表名(列)
删除索引
方式1
alter table xx
drop primary key;ALTER TABLE 表名 DROP INDEX 索引名;
方式2
drop index index_name on 表名;
查看索引
方式1
show create table 表名 ;方式2
show index from 表名;
创建全文索引
FULLTEXT 全文索引可以用于全文搜索,并且只为 CHAR 、VARCHAR、TEXT 列创建索引。索引总是对整个列进行,不支持局部(前缀)索引
create table table_1(
id int not null,
info varchar(255),
FULLTEXT INDEX | key fultxt_idx_info(info)
) engine=Myisam;
create table papers (
id int unsigned not null auto_increment,
title varchar(200), defualt null,
content text,
primary key( id ),
fulltext key title (title,content)
)engine = innodb default charset=utf8;lile 方式查询:
select * from papers where content like ‘%查询字符串%’;全文索引 用 match+against 方式查询:
select * from papers where match(title,content) against (‘查询字符串’);
- 全文索引比like + % 快N倍,但是可能存在精度问题;
- 如果需要全文索引的是大量数据,建议先添加数据,再创建索引。