首页 文章

mysql高CPU使用率(280%)

提问于
浏览
-1

嗨我的服务器CPU使用280%我的cnf文件

[mysqld_safe]
    socket      = /var/run/mysqld/mysqld.sock
    nice        = 0
    [mysqld]



    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
    skip-external-locking



    bind-address = 127.0.0.1


    thread_stack        = 192K
    thread_cache_size       = 32


    myisam-recover-options  = BACKUP


    query_cache_limit   = 128M



    log_error = /var/log/mysql/error.log



    expire_logs_days    = 1
    max_connections = 500

    max_user_connections = 500
    sort_buffer_size = 2M
    key_buffer_size = 128M
    tmp_table_size = 128M


    innodb_log_file_size = 16M


    skip-name-resolve=1


    max_connect_errors      = 100
    concurrent_insert       = 2
    connect_timeout         = 30

    query_cache_size = 32M
    query_cache_type = 0
    table_open_cache = 12000
    open_files_limit=24000

    wait_timeout = 14400
    interactive_timeout = 14400

    low_priority_updates = 1
    read_buffer_size = 5M
    log_queries_not_using_indexes = 1

我的mysql tunner输出

>>  MySQLTuner 1.7.7 - Major Hayden 
     >>  Bug reports, feature requests, and downloads at http://mysqltuner.com/
     >>  Run with '--help' for additional options and output filtering

    [--] Skipped version check for MySQLTuner script
    [OK] Logged in using credentials from debian maintenance account.
    [OK] Currently running supported MySQL version 5.7.21-0ubuntu0.16.04.1
    [OK] Operating on 64-bit architecture

    -------- Log file Recommendations ------------------------------------------------------------------
    [--] Log file: /var/log/mysql/error.log(83K)
    [OK] Log file /var/log/mysql/error.log exists
    [OK] Log file /var/log/mysql/error.log is readable.
    [OK] Log file /var/log/mysql/error.log is not empty
    [OK] Log file /var/log/mysql/error.log is smaller than 32 Mb

    -------- Storage Engine Statistics -----------------------------------------------------------------
    [--] Status: +ARCHIVE +BLACKHOLE +CSV -FEDERATED +InnoDB +MEMORY +MRG_MYISAM +MyISAM +PERFORMANCE_SCHEMA
    [--] Data in MyISAM tables: 120M (Tables: 4)
    [--] Data in InnoDB tables: 106M (Tables: 53)
    [OK] Total fragmented tables: 0

    -------- Security Recommendations ------------------------------------------------------------------
    [OK] There are no anonymous accounts for any database users
    [OK] All database users have passwords assigned
    [!!] User 'root@%' hasn't specific host restriction.
    [--] There are 612 basic passwords in the list.

    -------- CVE Security Recommendations --------------------------------------------------------------
    [OK] NO SECURITY CVE FOUND FOR YOUR VERSION

    -------- Performance Metrics -----------------------------------------------------------------------
    [--] Up for: 10m 44s (77K q [120.610 qps], 9K conn, TX: 754M, RX: 89M)
    [--] Reads / Writes: 78% / 22%
    [--] Binary logging is disabled
    [--] Physical Memory     : 49.1G
    [--] Max MySQL memory    : 4.8G
    [--] Other process memory: 494.7M
    [--] Total buffers: 320.0M global + 7.7M per thread (600 max threads)
    [--] P_S Max memory usage: 72B
    [--] Galera GCache Max memory usage: 0B
    [OK] Maximum reached memory usage: 3.3G (6.75% of installed RAM)
    [OK] Maximum possible memory usage: 4.8G (9.80% of installed RAM)
    [OK] Overall possible memory usage with other process is compatible with memory available
    [OK] Slow queries: 0% (0/77K)
    [OK] Highest usage of available connections: 66% (400/600)
    [OK] Aborted connections: 0.01%  (1/9317)
    [!!] Query cache may be disabled by default due to mutex contention.
    [!!] Query cache efficiency: 0.0% (0 cached / 46K selects)
    [OK] Query cache prunes per day: 0
    [OK] Sorts requiring temporary tables: 0% (0 temp sorts / 26 sorts)
    [OK] No joins without indexes
    [OK] Temporary tables created on disk: 0% (63 on disk / 9K total)
    [OK] Thread cache hit rate: 80% (1K created / 9K connections)
    [OK] Table cache hit rate: 92% (1K open / 1K opened)
    [OK] Open file limit used: 21% (225/1K)
    [!!] Table locks acquired immediately: 76%

    -------- Performance schema ------------------------------------------------------------------------
    [--] Memory used by P_S: 72B
    [--] Sys schema is installed.

    -------- ThreadPool Metrics ------------------------------------------------------------------------
    [--] ThreadPool stat is disabled.

    -------- MyISAM Metrics ----------------------------------------------------------------------------
    [!!] Key buffer used: 18.3% (24M used / 134M cache)
    [OK] Key buffer size / total MyISAM indexes: 128.0M/4.5M
    [OK] Read Key buffer hit rate: 99.9% (12K cached / 15 reads)
    [!!] Write Key buffer hit rate: 38.7% (1K cached / 416 writes)

    -------- InnoDB Metrics ----------------------------------------------------------------------------
    [--] InnoDB is enabled.
    [--] InnoDB Thread Concurrency: 0
    [OK] InnoDB File per table is activated
    [OK] InnoDB buffer pool / data size: 128.0M/106.4M
    [OK] Ratio InnoDB log file size / InnoDB Buffer pool size: 16.0M * 2/128.0M should be equal 25%
    [OK] InnoDB buffer pool instances: 1
    [--] Number of InnoDB Buffer Pool Chunk : 1 for 1 Buffer Pool Instance(s)
    [OK] Innodb_buffer_pool_size aligned with Innodb_buffer_pool_chunk_size & Innodb_buffer_pool_instances
    [OK] InnoDB Read buffer efficiency: 100.00% (366193213 hits/ 366199541 total)
    [OK] InnoDB Write log efficiency: 95.85% (219192 hits/ 228694 total)
    [OK] InnoDB log waits: 0.00% (0 waits / 9502 writes)

    -------- AriaDB Metrics ----------------------------------------------------------------------------
    [--] AriaDB is disabled.

    -------- TokuDB Metrics ----------------------------------------------------------------------------
    [--] TokuDB is disabled.

    -------- XtraDB Metrics ----------------------------------------------------------------------------
    [--] XtraDB is disabled.

    -------- RocksDB Metrics ---------------------------------------------------------------------------
    [--] RocksDB is disabled.

    -------- Spider Metrics ----------------------------------------------------------------------------
    [--] Spider is disabled.

    -------- Connect Metrics ---------------------------------------------------------------------------
    [--] Connect is disabled.

    -------- Galera Metrics ----------------------------------------------------------------------------
    [--] Galera is disabled.

    -------- Replication Metrics -----------------------------------------------------------------------
    [--] Galera Synchronous replication: NO
    [--] No replication slave(s) for this server.
    [--] Binlog format: ROW
    [--] XA support enabled: ON
    Use of uninitialized value $_[0] in concatenation (.) or string at
            mysqltuner.pl line 233 (#1)
        (W uninitialized) An undefined value was used as if it were already
        defined.  It was interpreted as a "" or a 0, but maybe it was a mistake.
        To suppress this warning assign a defined value to your variables.

        To help you figure out what was undefined, perl will try to tell you
        the name of the variable (if any) that was undefined.  In some cases
        it cannot do this, so it also tells you what operation you used the
        undefined value in.  Note, however, that perl optimizes your program
        and the operation displayed in the warning may not necessarily appear
        literally in your program.  For example, "that $foo" is usually
        optimized into "that " . $foo, and the warning will refer to the
        concatenation (.) operator, even though there is no . in
        your program.
    [--]
    [--]
    [--] This is a standalone server
    -------- Recommendations ---------------------------------------------------------------------------
    General recommendations:
        Control warning line(s) into /var/log/mysql/error.log file
        Control error line(s) into /var/log/mysql/error.log file
        Restrict Host for user@% to user@SpecificDNSorIp
        MySQL started within last 24 hours - recommendations may be inaccurate
        Optimize queries and/or use InnoDB to reduce lock wait
    Variables to adjust:
        query_cache_size (=0)
        query_cache_type (=0)
        query_cache_limit (> 128M, or use smaller result sets)

请帮我

1 回答

  • 0

    建议考虑你的my.cnf-ini [mysqld]部分

    max_connect_errors=10  # from 100 - do not be so liberal with hackers/crackers
    key_buffer_size=48M  # from 128M only 24M used
    query_cache_size=0  # from 32M to disable QC - insist on quality coding
    max_heap_table_size=128M  # should always be same as tmp_table_size
    innodb_buffer_pool_size=256M  # from 128M for growth of data/ndx's
    read_buffer_size=128K  # from 5M more than default is not necessary
    thread_cache_size=100  # from 32 to support > 1000 threads_created V8 CAP=100
    query_cache_limit=1K  # from 128M to conserve RAM and keep framework for QC
    query_cache_min_res_unit=512  # from 4096 for more efficient use of QC if ever used
    low_priority_updates=0  # from 1 for storage ASAP
    log_queries_not_using_indexes=0  # from 1 only use when FOCUS is specific to avoid intermingling with Slow Queries
    expire_logs_days=30  # from 1 V8 will default to 30 days
    log_warnings=2  # for addl information when connection fails
    

    当您想要查找不使用索引的查询时,

    long_query_time=5000  # yes, 5000 seconds and 
    min_examined_row_limit=1  # to avoid clutter
    log_queries_not_using_indexes=1
    

    然后,一小时后,回到正常的慢查询日志:

    long_query_time=nn  # whatever seconds you use typically
    min_examined_row_limit=0  # if that is your typical limit and
    log_queries_not_using_indexes=0   # for slow queries only
    

    如果您可以发布ulimit -a的文本结果,我们就会知道您正在使用的操作系统限制 .

    我们仍然想知道你的ulimit值设置为什么 .

相关问题