2011-03-14 39 views
2

为什么,当我运行分析MySQL表时提示错误1040 - 连接太多

ANALYZE TABLE table_name_here 

MySQL服务器启动给予了这个错误:

1040 - 连接太多

我已经运行这个通过PHPMyAdmin btw ..

该表包含超过1500万行数据。有没有办法来解决这个问题?

MySQLTuner结果:

-------- General Statistics -------------------------------------------------- 
[--] Skipped version check for MySQLTuner script 
[OK] Currently running supported MySQL version 5.0.91-rs-log 
[OK] Operating on 64-bit architecture 

-------- Storage Engine Statistics ------------------------------------------- 
[--] Status: +Archive -BDB +Federated -InnoDB -ISAM -NDBCluster 
[--] Data in MyISAM tables: 10G (Tables: 192) 
[!!] Total fragmented tables: 14 

-------- Security Recommendations ------------------------------------------- 
ERROR 1142 (42000) at line 1: SELECT command denied 
[OK] All database users have passwords assigned 

-------- Performance Metrics ------------------------------------------------- 
[--] Up for: 21m 37s (134K q [103.756 qps], 982 conn, TX: 267M, RX: 20M) 
[--] Reads/Writes: 88%/12% 
[--] Total buffers: 1.2G global + 22.2M per thread (120 max threads) 
[!!] Maximum possible memory usage: 3.8G (99% of installed RAM) 
[OK] Slow queries: 0% (4/134K) 
[OK] Highest usage of available connections: 14% (17/120) 
[OK] Key buffer size/total MyISAM indexes: 1.0G/2.9G 
[OK] Key buffer hit rate: 97.7% (1M cached/25K reads) 
[OK] Query cache efficiency: 72.7% (92K cached/127K selects) 
[OK] Query cache prunes per day: 0 
[OK] Sorts requiring temporary tables: 0% (0 temp sorts/6K sorts) 
[!!] Joins performed without indexes: 492 
[!!] Temporary tables created on disk: 44% (490 on disk/1K total) 
[OK] Thread cache hit rate: 98% (17 created/982 connections) 
[OK] Table cache hit rate: 97% (262 open/268 opened) 
[OK] Open file limit used: 0% (463/65K) 
[OK] Table locks acquired immediately: 99% (78K immediate/78K locks) 

-------- 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 
    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 *** 
    join_buffer_size (> 10.0M, or always use indexes with joins) 
    tmp_table_size (> 192M) 
    max_heap_table_size (> 192M) 

本来我的钥匙缓冲区的大小仅设置为64MB。当我将密钥缓冲区大小设置为1GB时,我的最大连接用户数仅在17时达到峰值,而运行该命令。当它只设置为64MB时,它总是达到允许的最大连接用户数。我无法将此设置为更高,因为我的服务器仅限于4GB RAM。

+0

http://rackerhacker.com/2008/06/24/mysql-error-1040-too-many-connections/ - 这是一个配置问题来分析表没有必然的关系。运行分析会锁定一个连接,并且如果您的运行接近您配置的限制,则会看到此问题。 –

+0

我已经添加MySQLTuner结果,我做了一些改变,我没有得到这“太多的连接”的错误了,当我运行的命令,但我得到一个MySQL的最大内存使用量是高危险的消息。我认为这与索引太大的表格有关。有任何解决这个问题的方法吗? – officeboi101

回答

1

我提出我的意见,以一个完整的答案在这里。这是一个MySQL配置问题,您可能会在服务器故障上得到更好的答案。

[分析表做了两两件事,会导致你的服务器的问题。首先,这是一个需要很长时间才能运行的命令。从你对问题的简要描述中,我猜你的应用程序正在与数据库进行很多短连接。由于ANALYZE需要很长时间,所以在运行时使用的连接被锁定。如果应用程序正在使用连接池或对应用程序的连接数限制了特定的应用程序限制,我会将其设置为短于MySQL连接限制的3倍,以便您可以像这样执行此类操作。

其次,ANALYZE TABLE,对于MyISAM表重建索引。这意味着MySQL尝试将整个表加载到内存中(或者读取整个表)以重新构建索引。这会对表发出表锁并占用大量内存,这会干扰MySQL执行其他工作(如运行应用程序)的能力。

我真正的建议将被移动到InnoDB的,而不是MyISAM数据。它在管理内存,索引和数据方面做得更好。对于您正在处理的表格大小和更少的头痛,它比MyISAM更快。