IT博客汇
  • 首页
  • 精华
  • 技术
  • 设计
  • 资讯
  • 扯淡
  • 权利声明
  • 登录 注册

    MySQL 管理工具集 percona-toolkit

    OurMySQL发表于 2016-04-17 17:46:38
    love 0

    apt-get install -y percona-toolkit

    # 检查重复索引
    pt-duplicate-key-checker -host=’sohu.dev.chenpeng.info’ -port=’43307′ -databases=’grape’

    # 运行状态监控
    pt-mysql-summary -host=’sohu.dev.chenpeng.info’ -port=’43307′ -databases=’grape’

    # 在线修改表结构
    pt-online-schema-change -host=’sohu.dev.chenpeng.info’ -port=’3306′ -alter “ADD COLUMN c1 INT” D=chenpeng_litchi,t=lc_operate_log -execute -print
    pt-online-schema-change -host=’sohu.dev.chenpeng.info’ -port=’3306′ -alter “ENGINE=InnoDB” D=chenpeng_litchi,t=lc_operate_log -execute -print

    # 格式化explain结果
    mysql -hsohu.dev.chenpeng.info -P43307 grape -e”explain SELECT a.line_id,b.dnf_source FROM gp_report_advertiser_day a INNER JOIN gp_line b ON a.line_id=b.id WHERE a.data_date=’2016-04-10′ LIMIT 100″ | pt-visual-explain

    重复索引结果示例:

    # ########################################################################
    # grape.gp_mars_report_advertiser_hour                                    
    # ########################################################################

    # line_id is a left-prefix of line_id_data_time
    # Key definitions:
    #   KEY `line_id` (`line_id`) USING BTREE,
    #   KEY `line_id_data_time` (`line_id`,`data_time`) USING BTREE
    # Column types:
    #      `line_id` bigint(20) unsigned not null comment ‘??id’
    #      `data_time` datetime not null comment ‘??’
    # To remove this duplicate index, execute:
    ALTER TABLE `grape`.`gp_mars_report_advertiser_hour` DROP INDEX `line_id`;

    # ########################################################################
    # grape.gp_operate_log                                                    
    # ########################################################################

    # related_id is a left-prefix of search3
    # Key definitions:
    #   KEY `related_id` (`related_id`),
    #   KEY `search3` (`related_id`,`opt_datetime`),
    # Column types:
    #      `related_id` int(10) unsigned not null comment ‘?????id’
    #      `opt_datetime` datetime not null comment ‘??????’
    # To remove this duplicate index, execute:
    ALTER TABLE `grape`.`gp_operate_log` DROP INDEX `related_id`;

    # ########################################################################
    # grape.gp_report_advertiser_hour                                        
    # ########################################################################

    # idx_line_id is a left-prefix of line_id_data_time
    # Key definitions:
    #   KEY `idx_line_id` (`line_id`),
    #   KEY `line_id_data_time` (`line_id`,`data_time`),
    # Column types:
    #      `line_id` bigint(20) not null
    #      `data_time` datetime not null
    # To remove this duplicate index, execute:
    ALTER TABLE `grape`.`gp_report_advertiser_hour` DROP INDEX `idx_line_id`;

    # ########################################################################
    # Summary of indexes                                                      
    # ########################################################################

    # Size Duplicate Indexes   48
    # Total Duplicate Indexes  3
    # Total Indexes            268

    工具检测到gp_operate_log有重复的索引,提供以下SQL语句删除重复的索引:

    ALTER TABLE `grape`.`gp_operate_log` DROP INDEX `related_id`;

    explain简化显示示例:

    root@ubuntu:/tmp/d3OnxmMr# mysql -hsohu.dev.chenpeng.info -P43307 -ugrapeuser -pfaf74223tr grape -e”explain SELECT a.line_id,b.dnf_source FROM gp_report_advertiser_day a INNER JOIN gp_line b ON a.line_id=b.id WHERE a.data_date=’2016-04-10′ LIMIT 100″ | pt-visual-explain
    JOIN
    +- Filter with WHERE
    |  +- Bookmark lookup
    |     +- Table
    |     |  table          b
    |     |  possible_keys  PRIMARY
    |     +- Unique index lookup
    |        key            b->PRIMARY
    |        possible_keys  PRIMARY
    |        key_len        4
    |        ref            grape.a.line_id
    |        rows           1
    +- Index lookup
      key            a->data_date
      possible_keys  line_id,data_date
      key_len        3
      ref            const
      rows           10722

    抱歉猜想失败,您看看下面的文章有用吗?

    • 2011 年 7 月 19 日 -- 探索MYSQL源代码-BINLOG里的时间
    • 2012 年 2 月 21 日 -- mysql如何定时执行
    • 2013 年 6 月 18 日 -- 二分查找(Binary Search)需要注意的问题,以及在数据库内核中的实现
    • 2013 年 1 月 8 日 -- MySQL数据库的字符集和copy_and_convert 字符集不同导致CPU资源额外消耗
    • 2009 年 6 月 24 日 -- Mysql服务器如何得到最佳性能优化
    • 2014 年 7 月 15 日 -- [MySQL优化案例]系列 — RAND()优化
    • 2008 年 9 月 21 日 -- MySQL主从同步:You need the REPLICATION SLAVE privilege for this operation
    • 2015 年 1 月 20 日 -- slave复制异常
    • 2008 年 10 月 14 日 -- MyISAM和InnoDB的异同
    • 2012 年 12 月 25 日 -- mysql监测工具


沪ICP备19023445号-2号
友情链接