当前位置: 移动技术网 > IT编程>数据库>Mysql > mysql-调优

mysql-调优

2020年03月11日  | 移动技术网IT编程  | 我要评论

mysql调优

1.选择合适的存储引擎

  • 经常用来读的表使用myisam引擎
  • 其余的表都使用innodb引擎

2.sql语句调优(尽量避免全表扫描)

  • 在select where order by常涉及到的字段上建立索引
  • where语句中不使用 !=,否则将放弃使用索引进行全表扫描
  • 尽量避免使用null值判断,否则会全表扫描
eg: select id from t1 where number is null 
优化:在number字段设置默认值0
  • 尽量避免用or来连接条件,否则会全表扫描
eg: select id from t1 where id=10 or id=20;
优化:select id from t1 where id=10
      union all
      select id from t1 where id=20;
  • 模糊查询尽量避免使用前置%,导致全表扫描
  • 尽量避免in 和 not in,导致全表扫描
eg: select id from t1 where id in(1,2,3)
优化:select id from t1 where id between 1 and 3;
  • 尽量避免使用select * from ....,要用具体的字段列表代替 *

如对本文有疑问, 点击进行留言回复!!

相关文章:

验证码:
移动技术网