欢迎投稿

今日深度:

mysql-调优,

mysql-调优,


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 ....,要用具体的字段列表代替 *

www.htsjk.Com true http://www.htsjk.com/Mysql/42392.html NewsArticle mysql-调优, mysql调优 1.选择合适的存储引擎 经常用来读的表使用myisam引擎 其余的表都使用innodb引擎 2.SQL语句调优(尽量避免全表扫描) 在select where order by常涉及到的字段上建立索引 whe...
相关文章
    暂无相关文章
评论暂时关闭