首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >分析MySQL表会产生错误1040 -连接太多

问分析MySQL表会产生错误1040 -连接太多
EN

Stack Overflow用户
提问于 2011-03-14 16:20:33
回答 1查看 1.7K关注 0票数 2

为什么我跑的时候

代码语言:javascript
复制
ANALYZE TABLE table_name_here

MySQL服务器开始发出以下错误:

1040 -太多连接

我已经通过PHPMyAdmin运行了..。

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

MySQLTuner结果:

代码语言:javascript
复制
-------- 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)

最初,我的密钥缓冲区大小仅设置为64 my。当我将键缓冲区大小设置为1GB时,在运行该命令时,我的最大连接用户数仅达到17。当它只被设置为64 it时,它总是达到允许连接的最大用户。我不能将其设置为更高的级别,因为我的服务器仅限于4GB内存。

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2011-03-21 19:43:10

我要把我的评论移到这里的完整答复。这是一个MySQL配置问题,您可能在服务器故障上得到更好的答案。

ANALYZE表做了两件会导致服务器问题的事情。首先,这是一个需要很长时间才能运行的命令。从您对这个问题的过于简短的描述中,我猜到您的应用程序正在做很多到数据库的短连接。因为分析需要很长时间,所以在运行时使用的连接被锁定。如果应用程序正在使用连接池,或者对它可以建立的连接数量有特定的应用程序限制,我将将其设置为MySQL连接限制之外的3个,以允许您执行这样的工作。

其次,分析表,为MyISAM表重新构建索引。这意味着MySQL试图将整个表加载到内存中(或读取整个表),以重新构建索引。这会使表锁定表并占用大量内存,这会影响MySQL执行其他工作的能力(比如运行应用程序)。

我真正的建议是搬到InnoDB,而不是MyISAM。它在管理内存、索引和数据方面做得更好。它比MyISAM更快,因为你正在处理的桌子尺寸和头痛较少。

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/5301361

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档