mysql调优

1.选择合适的存储引擎

SRE实战 互联网时代守护先锋,助力企业售后服务体系运筹帷幄!一键直达领取阿里云限量特价优惠。
  • 经常用来读的表使用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 ....,要用具体的字段列表代替 *
扫码关注我们
微信号:SRE实战
拒绝背锅 运筹帷幄