MYSQL 数据库优化

1、对查询进行优化,尽量避免全表扫描,首先考虑在where 或orderby 涉及的列建立索引。

2、where 后面不要使用null,否则引擎放弃索引,而经行全表扫描。可以在num列中默认设置为0确保num中没有null中,这样方便查询

3、where 后面尽量不要使用!= <> or in not in进行索引,这样数据库引擎也会放弃索引,而经行全表扫描 可以使用 nuion all

4、in(1,2,3,4) 尽量使用between 1 and 4代替

5、like “%aaa%”不会使用索引  但是 like  “aaa%” 可以使用索引

6、select id from t where num/2=100; 字段不要用来计算应改为 select id from t where num=100*2;

7、创建索引、复合索引、索引不要包含NULL的列、使用短索引、like语句操作、不要在列上进行运算、不要使用not in <>

原文地址:https://www.cnblogs.com/guwenren/p/3297811.html