MySQL 优化 - MySQL 的最大内存使用量非常高,但仍建议增加
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/23003626/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
MySQL Optimization - MySQL's maximum memory usage is dangerously high, but still recommending increases
提问by IsaacL
I have a cPanel/CentOS 6.5 VM with 12 GB RAM.
我有一个带有 12 GB RAM 的 cPanel/CentOS 6.5 VM。
I ran the MySQLTuner script, and followed the recommendations that they gave, but it's still recommending increases, while telling me that MySQL's maximum memory usage is dangerously high.
我运行了 MySQLTuner 脚本,并遵循了他们给出的建议,但它仍然建议增加,同时告诉我 MySQL 的最大内存使用量非常高。
My current config in my my.cnf file is:
我在 my.cnf 文件中的当前配置是:
[mysqld]
local-infile=0
query_cache_size=32M
innodb_file_per_table=1
open_files_limit=6740
default-storage-engine=MyISAM
tmpdir=/mysqltmp
group_concat_max_len=102400
tmp_table_size=64M
max_connections=500
interactive_timeout=30
wait_timeout=30
thread_cache_size = 16
thread_cache_size=16
table_cache=2000
join_buffer_size=32M
query_cache_limit=512M
key_buffer_size=128M
max_heap_table_size=32M
I restarted MySQL a short while ago to apply my most recent changes.
不久前我重新启动了 MySQL 以应用我最近的更改。
When I run the script, this is what I get:
当我运行脚本时,这就是我得到的:
>> MySQLTuner 1.3.0 - Major Hayden <[email protected]>
>> Bug reports, feature requests, and downloads at http://mysqltuner.com/
>> Run with '--help' for additional options and output filtering
[OK] Currently running supported MySQL version 5.5.36-cll
[OK] Operating on 64-bit architecture
-------- Storage Engine Statistics -------------------------------------------
[--] Status: +ARCHIVE +BLACKHOLE +CSV -FEDERATED +InnoDB +MRG_MYISAM
[--] Data in MyISAM tables: 551M (Tables: 467)
[--] Data in InnoDB tables: 49M (Tables: 908)
[--] Data in PERFORMANCE_SCHEMA tables: 0B (Tables: 17)
[--] Data in MEMORY tables: 0B (Tables: 37)
[!!] Total fragmented tables: 17
-------- Security Recommendations -------------------------------------------
[OK] All database users have passwords assigned
-------- Performance Metrics -------------------------------------------------
[--] Up for: 2h 6m 33s (379K q [49.933 qps], 2K conn, TX: 390M, RX: 115M)
[--] Reads / Writes: 51% / 49%
[--] Total buffers: 336.0M global + 34.6M per thread (500 max threads)
[!!] Maximum possible memory usage: 17.2G (148% of installed RAM)
[OK] Slow queries: 0% (0/379K)
[OK] Highest usage of available connections: 1% (5/500)
[OK] Key buffer size / total MyISAM indexes: 128.0M/125.7M
[OK] Key buffer hit rate: 100.0% (4M cached / 1K reads)
[OK] Query cache efficiency: 58.0% (145K cached / 251K selects)
[!!] Query cache prunes per day: 892777
[OK] Sorts requiring temporary tables: 0% (0 temp sorts / 10K sorts)
[!!] Joins performed without indexes: 3054
[!!] Temporary tables created on disk: 29% (6K on disk / 20K total)
[OK] Thread cache hit rate: 99% (5 created / 2K connections)
[OK] Table cache hit rate: 95% (1K open / 1K opened)
[OK] Open file limit used: 14% (999/6K)
[OK] Table locks acquired immediately: 99% (261K immediate / 261K locks)
[OK] InnoDB buffer pool / data size: 128.0M/49.1M
[OK] InnoDB log waits: 0
-------- Recommendations -----------------------------------------------------
General recommendations:
Run OPTIMIZE TABLE to defragment tables for better performance
MySQL started within last 24 hours - recommendations may be inaccurate
Reduce your overall MySQL memory footprint for system stability
Enable the slow query log to troubleshoot bad queries
Adjust your join queries to always utilize indexes
When making adjustments, make tmp_table_size/max_heap_table_size equal
Reduce your SELECT DISTINCT queries without LIMIT clauses
Variables to adjust:
*** MySQL's maximum memory usage is dangerously high ***
*** Add RAM before increasing MySQL buffer variables ***
query_cache_size (> 32M)
join_buffer_size (> 32.0M, or always use indexes with joins)
tmp_table_size (> 64M)
max_heap_table_size (> 32M)
If I increase those variables, I'll be even higher with memory usage.
如果我增加这些变量,内存使用率会更高。
Does anyone have any recommendations with what to do now?
有没有人对现在该怎么做有任何建议?
EDIT: Here are the results 14 hours after the last MySQL restart:
编辑:以下是上次 MySQL 重启后 14 小时的结果:
>> MySQLTuner 1.3.0 - Major Hayden <[email protected]>
>> Bug reports, feature requests, and downloads at http://mysqltuner.com/
>> Run with '--help' for additional options and output filtering
[OK] Currently running supported MySQL version 5.5.36-cll
[OK] Operating on 64-bit architecture
-------- Storage Engine Statistics -------------------------------------------
[--] Status: +ARCHIVE +BLACKHOLE +CSV -FEDERATED +InnoDB +MRG_MYISAM
[--] Data in MyISAM tables: 552M (Tables: 467)
[--] Data in InnoDB tables: 49M (Tables: 908)
[--] Data in PERFORMANCE_SCHEMA tables: 0B (Tables: 17)
[--] Data in MEMORY tables: 0B (Tables: 37)
[!!] Total fragmented tables: 21
-------- Security Recommendations -------------------------------------------
[OK] All database users have passwords assigned
-------- Performance Metrics -------------------------------------------------
[--] Up for: 14h 2m 3s (1M q [20.830 qps], 9K conn, TX: 1B, RX: 281M)
[--] Reads / Writes: 56% / 44%
[--] Total buffers: 336.0M global + 34.6M per thread (500 max threads)
[!!] Maximum possible memory usage: 17.2G (148% of installed RAM)
[OK] Slow queries: 0% (0/1M)
[OK] Highest usage of available connections: 1% (5/500)
[OK] Key buffer size / total MyISAM indexes: 128.0M/125.9M
[OK] Key buffer hit rate: 100.0% (15M cached / 1K reads)
[OK] Query cache efficiency: 76.3% (625K cached / 820K selects)
[!!] Query cache prunes per day: 250933
[OK] Sorts requiring temporary tables: 0% (0 temp sorts / 35K sorts)
[!!] Joins performed without indexes: 8623
[!!] Temporary tables created on disk: 31% (26K on disk / 82K total)
[OK] Thread cache hit rate: 99% (5 created / 9K connections)
[OK] Table cache hit rate: 58% (2K open / 3K opened)
[OK] Open file limit used: 17% (1K/6K)
[OK] Table locks acquired immediately: 99% (469K immediate / 469K locks)
[OK] InnoDB buffer pool / data size: 128.0M/49.1M
[OK] InnoDB log waits: 0
-------- Recommendations -----------------------------------------------------
General recommendations:
Run OPTIMIZE TABLE to defragment tables for better performance
MySQL started within last 24 hours - recommendations may be inaccurate
Reduce your overall MySQL memory footprint for system stability
Enable the slow query log to troubleshoot bad queries
Adjust your join queries to always utilize indexes
When making adjustments, make tmp_table_size/max_heap_table_size equal
Reduce your SELECT DISTINCT queries without LIMIT clauses
Variables to adjust:
*** MySQL's maximum memory usage is dangerously high ***
*** Add RAM before increasing MySQL buffer variables ***
query_cache_size (> 32M)
join_buffer_size (> 32.0M, or always use indexes with joins)
tmp_table_size (> 64M)
max_heap_table_size (> 32M)
Thanks a lot!
非常感谢!
回答by Zafar Malik
Change your config file as per below suggestion and check-
根据以下建议更改您的配置文件并检查-
[mysqld]
local-infile=0
query_cache_size=32M
innodb_file_per_table -- Just update innodb_file_per_table instead of =1
open_files_limit=6740 -- only 14% is using, so you can reduce it to 1500, to use your RAM in better way.
default-storage-engine=MyISAM
tmpdir=/mysqltmp
group_concat_max_len=102400
tmp_table_size=64M
max_connections=500 -- as per your error report, only 3 are in use so you can set it to 100. As it will use memory un-neccesorily.
interactive_timeout=30
wait_timeout=30
thread_cache_size = 16
table_cache=2000
join_buffer_size=32M
query_cache_limit=512M -- It should be less then query_cache_size, so keep it max. 10M
key_buffer_size=128M -- keep it 25% of your total RAM but not greater than 3 GB for Myisam engine, so in your case set is 3G.
max_heap_table_size=32M -- your server will use total memory for temp tables which ever will be lesser out of tmp_table_size, max_
回答by Erico
Does your server really need 500 multiple connections ? If it doesn't, you can change this setting to a proper value.
您的服务器真的需要 500 个多重连接吗?如果没有,您可以将此设置更改为适当的值。
The script basically multiplies max_connectionswith some settings. A thread needs to allocate some memory for itself (1 connection = 1 thread). Some settings that are used per thread: thread_stack, net_buffer_length, ...
该脚本基本上将max_connections与一些设置相乘。一个线程需要为自己分配一些内存(1 个连接 = 1 个线程)。每个线程使用的一些设置:thread_stack、net_buffer_length、...
More information: https://dev.mysql.com/doc/refman/5.6/en/memory-use.html
更多信息:https: //dev.mysql.com/doc/refman/5.6/en/memory-use.html