关于SQL

创建索引

create index 索引名字 on 表名 (列1,列2)

定位慢查询

执行计划

explain select * from user

结果如下,type为ALL说明是全表扫描,如果是ref则是使用了索引

把id加上索引,之后根据id执行计划,会如图所示,type为ref,使用了索引。如果是const,则是主键通过主键

explain select * from user where id=95

select * from user where name like '%%' 这样不会用索引

select * from user where name like '%%' 这样不会用索引

原文地址:https://www.cnblogs.com/bxssjava/p/10152773.html