Home  >  Article  >  Database  >  Introduction to Mysql optimization methods

Introduction to Mysql optimization methods

不言
不言forward
2018-12-30 09:57:505864browse

This article brings you an introduction to the optimization method of Mysql. It has certain reference value. Friends in need can refer to it. I hope it will be helpful to you.

1. Application access optimization

1).减少数据访问(Nosql作用)
2).返回更少数据
3).减少交互次数(Nosql作用)

2. Server hardware selection

1).数据SSD (固态)
2).日志SAS (企业级)

3. Operating system optimization (LINUX/SWAP (virtual memory))

1).LINUX 
2).设置SWAP(虚拟内存)
3).关闭NUMA特性
4).网卡优化(双网卡做成BOND(0 / 1 / 6)或者调整网络参数)
5).磁盘调度设置(DEADLINE / NOOP / CFQ)
6).文件系统(XFS / EXT4 / NOATIME / NOBARRIER)

4. Database optimization

1).数据库实例化优化
2).SQL语句优化
    a).选着有效的连接顺序(from从左到右;where从下而上,从右到左;group by,order by从左到右)
    b).避免产生笛卡尔积
    c).避免使用*(需要查询数据字典)
    d).用where子句替换having子句
    e).in适合外表大而内表小;exist适合于外表小而内表大
    f).使用exists替代distinct
    g).避免隐式数据类型转换
    h).使用索引来避免排序操作
    i).尽量使用前端匹配的模糊查找(Column like ‘ABC%’)
    j).不要在选择性较低的字段建立索引
    k).避免对列操作(where条件中对字段进行数学表达式运算)
    l).尽量去掉in , or ,<> (索引失效)
    m).避免在索引列上使用 is null 或者 not
    n).批量提交sql

The above is the detailed content of Introduction to Mysql optimization methods. For more information, please follow other related articles on the PHP Chinese website!

Statement:
This article is reproduced at:segmentfault.com. If there is any infringement, please contact admin@php.cn delete