MySQL优化建议

时间:2019-12-22 15:55:57

标签: mysql server config

我有一个Directadmin / CentOS 7.0专用服务器,具有128 GB RAM和2个CPU 10核心2.0 GHz,

我运行了MySQLTuner脚本,并遵循了他们给出的建议,但是仍然建议增加,同时告诉我MySQL的最大内存使用率非常高。

我的my.cnf文件中的当前配置为:

C++

这是my.cnf配置

>>  MySQLTuner 1.7.19 - Major Hayden <major@mhtx.net>
 >>  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] Currently running supported MySQL version 10.4.11-MariaDB
[OK] Operating on 64-bit architecture

-------- Log file Recommendations ------------------------------------------------------------------
[OK] Log file /var/log/mysql.log exists
[--] Log file: /var/log/mysql.log(0B)
[OK] Log file /var/log/mysql.log is readable.
[!!] Log file /var/log/mysql.log is empty
[OK] Log file /var/log/mysql.log is smaller than 32 Mb
[OK] /var/log/mysql.log doesn't contain any warning.
[OK] /var/log/mysql.log doesn't contain any error.
[--] 0 start(s) detected in /var/log/mysql.log
[--] 0 shutdown(s) detected in /var/log/mysql.log

-------- Storage Engine Statistics -----------------------------------------------------------------
[--] Status: +Aria +CSV +InnoDB +MEMORY +MRG_MyISAM +MyISAM +PERFORMANCE_SCHEMA +SEQUENCE
[--] Data in MyISAM tables: 426.0M (Tables: 34)
[--] Data in InnoDB tables: 175.6M (Tables: 29)
[OK] Total fragmented tables: 0

-------- Analysis Performance Metrics --------------------------------------------------------------
[--] innodb_stats_on_metadata: OFF
[OK] No stat updates during querying INFORMATION_SCHEMA.

-------- Security Recommendations ------------------------------------------------------------------
[OK] There are no anonymous accounts for any database users
[OK] All database users have passwords assigned
[!!] There is no basic password file list!

-------- CVE Security Recommendations --------------------------------------------------------------
[--] Skipped due to --cvefile option undefined

-------- Performance Metrics -----------------------------------------------------------------------
[--] Up for: 22m 0s (2M q [2K qps], 3K conn, TX: 2G, RX: 317M)
[--] Reads / Writes: 99% / 1%
[--] Binary logging is disabled
[--] Physical Memory     : 125.7G
[--] Max MySQL memory    : 131098.3G
[--] Other process memory: 0B
[--] Total buffers: 15.6G global + 32.0G per thread (4096 max threads)
[--] P_S Max memory usage: 0B
[--] Galera GCache Max memory usage: 0B
[!!] Maximum reached memory usage: 271.7G (216.19% of installed RAM)
[!!] Maximum possible memory usage: 131098.3G (104328.03% of installed RAM)
[!!] Overall possible memory usage with other process exceeded memory
[OK] Slow queries: 0% (0/2M)
[OK] Highest usage of available connections: 0% (8/4096)
[OK] Aborted connections: 0.00%  (0/3914)
[!!] name resolution is active : a reverse name resolution is made for each new connection and can reduce performance
[!!] Query cache may be disabled by default due to mutex contention.
[OK] Query cache efficiency: 48.9% (2M cached / 5M selects)
[OK] Query cache prunes per day: 0
[OK] Sorts requiring temporary tables: 0% (0 temp sorts / 43K sorts)
[!!] Joins performed without indexes: 415
[!!] Temporary tables created on disk: 64% (8K on disk / 12K total)
[OK] Thread cache hit rate: 99% (8 created / 3K connections)
[OK] Table cache hit rate: 96% (187 open / 193 opened)
[OK] table_definition_cache(400) is upper than number of tables(329)
[OK] Open file limit used: 0% (148/20K)
[OK] Table locks acquired immediately: 99% (70K immediate / 70K locks)

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

-------- ThreadPool Metrics ------------------------------------------------------------------------
[--] ThreadPool stat is enabled.
[--] Thread Pool Size: 40 thread(s).
[--] Using default value is good enough for your version (10.4.11-MariaDB)

-------- MyISAM Metrics ----------------------------------------------------------------------------
[!!] Key buffer used: 23.4% (125M used / 536M cache)
[OK] Key buffer size / total MyISAM indexes: 512.0M/53.6M
[OK] Read Key buffer hit rate: 100.0% (121M cached / 27K reads)
[OK] Write Key buffer hit rate: 99.8% (636 cached / 635 writes)

-------- InnoDB Metrics ----------------------------------------------------------------------------
[--] InnoDB is enabled.
[--] InnoDB Thread Concurrency: 0
[OK] InnoDB File per table is activated
[OK] InnoDB buffer pool / data size: 8.0G/175.6M
[OK] Ratio InnoDB log file size / InnoDB Buffer pool size: 1.0G * 2/8.0G should be equal to 25%
[OK] InnoDB buffer pool instances: 8
[--] Number of InnoDB Buffer Pool Chunk : 64 for 8 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: 99.99% (58380753 hits/ 58389392 total)
[!!] InnoDB Write Log efficiency: 125.23% (139 hits/ 111 total)
[OK] InnoDB log waits: 0.00% (0 waits / 250 writes)

-------- AriaDB Metrics ----------------------------------------------------------------------------
[--] AriaDB is enabled.
[OK] Aria pagecache size / total Aria indexes: 128.0M/368.0K
[OK] Aria pagecache hit rate: 97.7% (357K cached / 8K reads)

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

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

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

-------- Replication Metrics -----------------------------------------------------------------------
[--] Galera Synchronous replication: NO
[--] No replication slave(s) for this server.
[--] Binlog format: MIXED
[--] XA support enabled: ON
[--] Semi synchronous replication Master: OFF
[--] Semi synchronous replication Slave: OFF
[--] This is a standalone server

-------- Recommendations ---------------------------------------------------------------------------
General recommendations:
    MySQL was started within the last 24 hours - recommendations may be inaccurate
    Reduce your overall MySQL memory footprint for system stability
    Dedicate this server to your database for highest performance.
    Configure your accounts with ip or subnets only, then update your configuration with skip-name-resolve=1
    We will suggest raising the 'join_buffer_size' until JOINs not using indexes are found.
             See https://dev.mysql.com/doc/internals/en/join-buffer-size.html
             (specially the conclusions at the bottom of the page).
    Temporary table size is already large - reduce result set size
    Reduce your SELECT DISTINCT queries without LIMIT clauses
    Performance schema should be activated for better diagnostics
Variables to adjust:
  *** MySQL's maximum memory usage is dangerously high ***
  *** Add RAM before increasing MySQL buffer variables ***
    query_cache_size (=0)
    query_cache_type (=0)
    join_buffer_size (> 32.0G, or always use indexes with JOINs)
    performance_schema = ON enable PFS

有人对现在的工作有什么建议吗?

3 个答案:

答案 0 :(得分:1)

join_buffer_size=32G在我看来似乎很高,并且可能是内存警告的原因,尤其是考虑到max_connections = 4096并且MySQLTuner基本上将这两个数字相乘以估算内存消耗。我认为max_connections也很高,根据目前提供的信息,距离要求还很远,请参阅Highest usage of available connections: 0% (8/4096)

MySQLTuner给出了一些有关查询改进的提示,我将首先关注。 (确保JOIN使用索引,减小结果集的大小,…)

然后,重新启动服务器,并使其运行24小时。然后再次运行MySQLTuner以获得新的建议。

答案 1 :(得分:0)

建议您考虑my.cnf [mysqld]部分

max_connections = 256
key_buffer_size = 192M
max_allowed_packet = 1024M
query_cache_limit = 1M
query_cache_size = 96M
query_cache_type = 1
queyr_cache_min_res_unit=512
innodb_log_file_size=1G
innodb_log_buffer_size=512M
innodb_buffer_pool_size=1G
max_heap_table_size=64M
join_buffer_size=256K
tmp_table_size=64M
thread_cache_size=256
performance_schema=ON
skip_name_resolve=1

这些更改将显着减少MySQLTuner计算的最大可用内存使用量131 TB,并在TOP报告时减少CPU繁忙。

免责声明:我是个人资料(网络个人资料)中提到的网站的内容作者,在该资料中,我们有可下载的免费实用程序脚本,可帮助您进行性能调整,常见问题解答和联系信息。

答案 2 :(得分:0)

请勿盲目增加设置,否则很可能会用完RAM,并且由于交换而无法使用,甚至崩溃。

max_connections = 4096  --> 500
key_buffer_size = 512M  --> If not using MyISAM, lower to 20M
query_cache_size = 5G     --> This is terrible (unless on Aurora).  Lower to 50M
query_cache_limit = 256M  --> ditto
innodb_buffer_pool_size=8G  --> 100G, since the 128G is dedicated for MySQL
max_heap_table_size=2G   --> 1G
tmp_table_size=2G        --> 1G
join_buffer_size=32G   --> 1G
thread_cache_size=512  --> 50

“最大内存”警告是虚假的。没有准确的公式。尽管如此,它仍然为您指明了正确的方向。

mysqltuner有一些缺陷。有些很难避免。 (例如,一件事说提高xyz,另一件事说降低xyz。哪个应该赢?)

如果您希望进行其他分析,请参见http://mysql.rjweb.org/doc.php/mysql_analysis