调整mysql。我应该使用哪些mysqltuner建议?

时间:2018-06-04 12:10:14

标签: mysql multithreading

下午好。 该站点位于VPS(10 GB RAM,2 CPU核心,65 GB SSD)上。 我把mysqltuner和有关配置mysql的建议。 我想澄清应该采用哪些建议来获得性能。 什么值将mysql放到参数中?

当前的Mysql设置


    [client]
    port        = 3306
    socket      = /var/run/mysqld/mysqld.sock

    [mysqld_safe]
    log-error=/var/log/mysql.log
    pid-file    = /var/run/mysqld/mysqld.pid
    socket      = /var/run/mysqld/mysqld.sock
    nice        = 0

    [mysqld]
    local-infile=0
    user        = mysql
    pid-file    = /var/run/mysqld/mysqld.pid
    socket      = /var/run/mysqld/mysqld.sock
    port        = 3306
    basedir     = /usr
    datadir     = /var/lib/mysql
    tmpdir      = /tmp
    lc-messages-dir = /usr/share/mysql
    explicit_defaults_for_timestamp

    # Instead of skip-networking the default is now to listen only on
    # localhost which is more compatible and is not less secure.
    bind-address    = 127.0.0.1

    log-error   = /var/log/mysql/error.log

    # Recommended in standard MySQL setup
    sql_mode=NO_ENGINE_SUBSTITUTION,STRICT_TRANS_TABLES

    # Disabling symbolic-links is recommended to prevent assorted security risks
    symbolic-links=0

    # * IMPORTANT: Additional settings that can override those from this file!
    #   The files must end with '.cnf', otherwise they'll be ignored.
    #
    !includedir /etc/mysql/conf.d/
    innodb-buffer-pool-instances = 2
    innodb-buffer-pool-size = 2361393152
    innodb-flush-log-at-trx-commit = 2
    innodb-log-file-size = 524288000
    innodb-thread-sleep-delay = 0
    join-buffer-size = 8388608
    max-connections = 100
    max-heap-table-size = 268435456
    query-cache-limit = 2097152
    query-cache-size = 67108864
    query-cache-type = ON
    skip-name-resolve = TRUE
    sort-buffer-size = 8388608
    symbolic-links = FALSE
    tmp-table-size = 268435456

Mysqltuner参考


     >>  MySQLTuner 1.3.0 - Major Hayden 
     >>  Bug reports, feature requests, and downloads at http://mysqltuner.com/
     >>  Run with '--help' for additional options and output filtering
    [OK] Logged in using credentials from debian maintenance account.
    [OK] Currently running supported MySQL version 5.6.35
    [OK] Operating on 64-bit architecture

    -------- Storage Engine Statistics -------------------------------------------
    [--] Status: +ARCHIVE +BLACKHOLE +CSV -FEDERATED +InnoDB +MRG_MYISAM
    [--] Data in InnoDB tables: 2G (Tables: 326)
    [--] Data in PERFORMANCE_SCHEMA tables: 0B (Tables: 52)
    [--] Data in MyISAM tables: 46M (Tables: 5)
    [!!] Total fragmented tables: 20

    -------- Security Recommendations  -------------------------------------------
    [OK] All database users have passwords assigned

    -------- Performance Metrics -------------------------------------------------
    [--] Up for: 39d 21h 6m 2s (587M q [170.642 qps], 16M conn, TX: 1078B, RX: 358B)
    [--] Reads / Writes: 75% / 25%
    [--] Total buffers: 2.5G global + 16.6M per thread (100 max threads)
    [OK] Maximum possible memory usage: 4.2G (41% of installed RAM)
    [OK] Slow queries: 0% (1K/587M)
    [OK] Highest usage of available connections: 40% (40/100)
    [OK] Key buffer size / total MyISAM indexes: 8.0M/32.6M
    [OK] Key buffer hit rate: 99.5% (136M cached / 677K reads)
    [OK] Query cache efficiency: 81.7% (395M cached / 484M selects)
    [!!] Query cache prunes per day: 1080995
    [OK] Sorts requiring temporary tables: 0% (473 temp sorts / 27M sorts)
    [!!] Joins performed without indexes: 22423559
    [!!] Temporary tables created on disk: 33% (8M on disk / 25M total)
    [OK] Thread cache hit rate: 99% (158K created / 16M connections)
    [OK] Table cache hit rate: 79% (985 open / 1K opened)
    [OK] Open file limit used: 0% (62/16K)
    [OK] Table locks acquired immediately: 99% (390M immediate / 390M locks)
    [OK] InnoDB buffer pool / data size: 2.2G/2.2G
    [!!] InnoDB log waits: 5
    -------- Recommendations -----------------------------------------------------
    General recommendations:
        Run OPTIMIZE TABLE to defragment tables for better performance
        Adjust your join queries to always utilize indexes
        Temporary table size is already large - reduce result set size
        Reduce your SELECT DISTINCT queries without LIMIT clauses
    Variables to adjust:
        query_cache_size (> 64M)
        join_buffer_size (> 8.0M, or always use indexes with joins)
        innodb_log_buffer_size (>= 8M)

2 个答案:

答案 0 :(得分:0)

从最初的可用信息中获取my.cnf-ini [mysqld]的建议

    public void MyFunction( <figure out what params you need here> )
    {
        … code goes here
    }

研究需要找到没有指数的JOINS在39天内有2200万人被忽略了很多。 EXPLAIN SELECT ...将帮助您找到它们。

请在时间允许的情况下发布取得的进展。

如需其他帮助,请在我的个人资料中查找联系信息。

答案 1 :(得分:0)

由于我们对主机上其他组件对系统的要求一无所知,因此无法就调整任何内存使用情况提出建议。

“没有索引执行的连接”表示您存在架构问题。写入的比例非常高,表明您可能有更多基本问题(例如草率的ORM)。您尚未设置long_query_time。虽然报告的查询比例很慢,但考虑到机器处理的工作量,这不是一个非常逼真的图片。您应该将long_query_time应用为零并收集数据一段时间,以了解您的性能/容量问题的真实情况。