Wordpress无法在非常小的站点中连接到DB:Too Many Connections

时间:2014-04-19 19:30:34

标签: php mysql wordpress

我在WordPress中建立一个网站,在本周它开始崩溃Error establishing a database connection消息。我创建了一个只连接到数据库的测试档案,它告诉我错误是"连接太多"

我非常确定我是唯一一个访问该网站的人(我还在开发它,并且apache日志不会显示更多访问次数),WordPress备份Dropbox插件是我认为可以使用数据库的唯一一个,但我仍然认为我不应该看到这个错误。

"输出显示进程列表"只向我显示" show processlist"查询。

"的输出显示状态,如'%con'"是这样的:

+----------------------------------------+--------+
| Variable_name                          | Value  |
+----------------------------------------+--------+
| Aborted_connects                       | 41002  |
| Com_show_contributors                  | 0      |
| Connections                            | 337541 |
| Max_used_connections                   | 152    |
| Performance_schema_cond_classes_lost   | 0      |
| Performance_schema_cond_instances_lost | 0      |
| Ssl_client_connects                    | 0      |
| Ssl_connect_renegotiates               | 0      |
| Ssl_finished_connects                  | 0      |
| Threads_connected                      | 151    |
+----------------------------------------+--------+

连接的线程似乎始终处于最大值

我该怎么办?这是服务器问题吗?

编辑:因为@JakeGould建议我运行一个MySQL Tuning Primer脚本,但它因连接错误而死亡,输出如下:

        -- MYSQL PERFORMANCE TUNING PRIMER --
             - By: Matthew Montgomery -

MySQL Version 5.5.36-cll x86_64

Uptime = 0 days 0 hrs 56 min 33 sec
Avg. qps = 59
Total Questions = 200437
Threads Connected = 151

Warning: Server has not been running for at least 48hrs.
It may not be safe to use these recommendations

To find out more information on how each of these
runtime variables effects performance visit:                                                                                                                                                    
http://dev.mysql.com/doc/refman/5.5/en/server-system-variables.html
Visit http://www.mysql.com/products/enterprise/advisors.html
for info about MySQL's Enterprise Monitoring and Advisory Service

SLOW QUERIES
The slow query log is NOT enabled.
Current long_query_time = 10.000000 sec.
You have 4127 out of 200644 that take longer than 10.000000 sec. to complete
Your long_query_time seems to be fine

BINARY UPDATE LOG
The binary update log is NOT enabled.
You will not be able to do point in time recovery
See http://dev.mysql.com/doc/refman/5.5/en/point-in-time-recovery.html

WORKER THREADS
Current thread_cache_size = 0
Current threads_cached = 0
Current threads_per_sec = 4
Historic threads_per_sec = 2
Threads created per/sec are overrunning threads cached
You should raise thread_cache_size                                                                                                                                                              

MAX CONNECTIONS
Current max_connections = 151
Current threads_connected = 150
Historic max_used_connections = 152
The number of used connections is 100% of the configured maximum.
You should raise max_connections

INNODB STATUS
Current InnoDB index space = 448 K
Current InnoDB data space = 3 M
Current InnoDB buffer pool free = 82 %
Current innodb_buffer_pool_size = 128 M
Depending on how much space your innodb indexes take up it may be safe
to increase this value to up to 2 / 3 of total system memory

ERROR 1040 (08004): Too many connections

2 个答案:

答案 0 :(得分:0)

我过去曾经发生这种情况。有可能有许多站点使用pconnect共享相同的服务器/数据库。特别是在共享托管解决方案上,最好使用标准连接。因此,mysql_pconnect()改为使用mysql_connect()

答案 1 :(得分:0)

这是专用服务器吗?还是共享主机?甚至是共享数据库池?

虽然我的直觉说这不是一个简单的性能调优问题,但我仍然建议使用MySQL Tuning Primer Script located here来查看它是否显示有关您的设置的任何奇怪内容。非常容易使用&这些建议非常适合。

根据您的设置,您可能需要了解如何通过手动进行性能调整 - 这意味着您将学会自己解释MySQL输出并对其进行操作 - 但此脚本可以很好地用于我曾经使用它们的95%的设置。另外5%是数据库特性设置,需要更多的自定义护理。我强烈推荐像this one on the MySQL performance blog这样的教程。

此外,this site has a nice compilation您可以采取哪些措施来解决在WordPress中专门连接数据库时遇到的问题。