mysql中索引的使用

it2022-05-05  161

**

索引

** 我们在使用sql时,在遇到sql性能下降、执行时间长时,就需要考虑用索引来帮我们解决问题。如,数据过多,关联太多的表等。

创建索引 create index idx_name_age_address on student(name,age,address);

create table student( id int(10) auto_increment, name varchar(20) , age int(3), address varchar(200) , class varchar(3) , primary key(id), key(name), unique(name), key(name,address) );

删除索引 drop index idx_name,age,address on student;

查看索引 show index from student;

查看是否使用索引 explain select sql_no_cache * from student where name=‘张三’; 注:sql_no_cache不使用缓存来查询。

索引使用失败的场景。

使用不等于(!=或<>)时使用is not nulllike以通配符开头(’%三‘)字符串不加单引号

最新回复(0)