zoukankan      html  css  js  c++  java
  • mysql性能优化学习笔记(4)索引的优化


    一、选择合适的索引列
         1.在where,group by,order by,on从句中出现的列
         2.索引字段越小越好(因为数据库的存储单位是页,一页中能存下的数据越多越好 )
         3.离散度大得列放在联合索引前面
    select count(distinct customer_id), count(distinct staff_id) from payment;
    查看离散度 通过统计不同的列值来实现 count越大 离散程度越高


    二、寻找索引优化的方法
    安装方法:
    [root@localhost-centos6 ~]# wget percona.com/get/pt-duplicate-key-checker
    [root@localhost-centos6 ~]# chmod u+x  pt-duplicate-key-checker
    [root@localhost-centos6 ~]# mv pt-duplicate-key-checker /usr/bin/

    使用方法:
    pt-duplicate-key-checker -uroot -p '123456' -h 127.0.0.1

    三、维护索引
    通过慢查询日志配合pt-index-usage来删除不用索引:pt-index-usage -uroot -p '' mysql-slow.log
    pt-index-usage -uroot -p '123456' -h 127.0.0.1 /var/lib/mysql/localhost-centos6-slow.log
    注意:主从数据库中需要几何所有的慢查询日志,比较全面。

    索引优化是mysql数据库的优化重点,这里只是作为一个提纲作用,以后还会继续研究。

  • 相关阅读:
    H
    并查集
    H
    Supermarket (贪心 并查集)
    H
    M
    N-Find a way
    HDU 4035 Maze
    #386. 【UNR #3】鸽子固定器
    P4688 [Ynoi2016]掉进兔子洞
  • 原文地址:https://www.cnblogs.com/haodaquan/p/4986573.html
Copyright © 2011-2022 走看看