php,mysql - 连接数据库错误太多 [英] php, mysql - Too many connections to database error

查看:318
本文介绍了php,mysql - 连接数据库错误太多的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

所有人都有美好的一天。我有一个奇怪的错误。我创建了一个如下所示的聊天:




  • 问题/答案已插入到db

  • 每2秒向一个获取新问题/答案的PHP脚本发送一个ajax请求



得到此错误:

 未捕获异常'PDOException'带有消息'SQLSTATE [HY000] [1040] /www/html/dbdev/include/Zend/Db/Adapter/Pdo/Abstract.php:129 
堆栈跟踪:#0 / var / www / html / dbdev / include / Zend / Db / Adapter / Pdo / Abstract.php(129):PDO-> __ construct('mysql:host = loca ...','','',Array)
s#1 / var / www / html / dbdev / include / Zend /Db/Adapter/Pdo/Mysql.php(96):Zend_Db_Adapter_Pdo_Abstract-> _connect()
s#2 /var/www/html/dbdev/include/Zend/Db/Adapter/Abstract.php(448) :Zend_Db_Adapter_Pdo_Mysql-> _connect()
s#3 /var/www/html/dbdev/include/Zend/Db/Adapter/Pdo/Abstract.php(238):Zend_Db_Adapter_Abstract-> query('select profile_。 ..',Array)
s#4 /var/www/html/dbdev/include/Zend/Db/Adapter/Abstract.php(782):Zend_Db_Adapter_Pdo_Abstract-> query('select profile _...' Array)
s#5 /var/www/html/dbdev/include/Profile.php(43):Zend_Db_Adapter_Abstract-> fetchPairs('select profile _...')
s#6 / var / www /html/dbdev/public_html/index.php(29):profile-> load()
s#7 {main}下一个异常'Zend_Db_Adapter_Exception'在/ var / www / html / dbdev / include / Zend / Db / Adapter / Pdo / Abstract.php on line 144

问题是我们不是那么多...(8)我不认为数据库不能同时支持超过8到16个连接(规范写道,聊天必须支持50-100用户,所以8是...小)。



所以... any1告诉我为什么会发生这种情况(昨天我们是15和工作正常),如何解决呢?感谢您的帮助。如果你需要任何代码示例只是问。

解决方案

Too Many Connections错误有很多不同的原因。



请访问MySQL.com上的此常见问题页面: http: //dev.mysql.com/doc/refman/5.5/en/too-many-connections.html



检查my.cnf文件中的 max_connections。如果没有,尝试:

  [mysqld] 
set-variable = max_connections = 250



但是默认值是151,所以你应该没问题。



您在共享主机上,可能是其他用户占用太多连接。



其他需要注意的问题是使用持久连接和耗尽的磁盘空间。


Good day to all. I have an odd error. I have created a chat that works like this:

  • questions/answers are inserted into a db
  • every 2 seconds an ajax request is sent to a php script that fetch the new questions/answers

It worked fine until today when I got this error:

Uncaught exception 'PDOException' with message 'SQLSTATE[HY000] [1040] Too many connections' in /var/www/html/dbdev/include/Zend/Db/Adapter/Pdo/Abstract.php:129 
Stack trace: #0 /var/www/html/dbdev/include/Zend/Db/Adapter/Pdo/Abstract.php(129): PDO->__construct('mysql:host=loca...', '', '', Array) 
s#1 /var/www/html/dbdev/include/Zend/Db/Adapter/Pdo/Mysql.php(96): Zend_Db_Adapter_Pdo_Abstract->_connect() 
s#2 /var/www/html/dbdev/include/Zend/Db/Adapter/Abstract.php(448): Zend_Db_Adapter_Pdo_Mysql->_connect() 
s#3 /var/www/html/dbdev/include/Zend/Db/Adapter/Pdo/Abstract.php(238): Zend_Db_Adapter_Abstract->query('select profile_...', Array) 
s#4 /var/www/html/dbdev/include/Zend/Db/Adapter/Abstract.php(782): Zend_Db_Adapter_Pdo_Abstract->query('select profile_...', Array) 
s#5 /var/www/html/dbdev/include/Profile.php(43): Zend_Db_Adapter_Abstract->fetchPairs('select profile_...') 
s#6 /var/www/html/dbdev/public_html/index.php(29): Profile->load() 
s#7 {main} Next exception 'Zend_Db_Adapter_Exception' with in /var/www/html/dbdev/include/Zend/Db/Adapter/Pdo/Abstract.php on line 144

The problem is that we were not that many... (8) and I don't think the db could not support more than 8 to 16 connections simultaneously (on specifications is written that the chat must support 50-100 users so 8 is... small).

So... can any1 tell me why did this happen (yesterday we were 15 and worked fine) and how to solve it? Thank you for your help. If you need any code samples just ask.

解决方案

There are a bunch of different reasons for the "Too Many Connections" error.

Check out this FAQ page on MySQL.com: http://dev.mysql.com/doc/refman/5.5/en/too-many-connections.html

Check your my.cnf file for "max_connections". If none exist try:

[mysqld]
set-variable=max_connections=250

However the default is 151, so you should be okay.

If you are on a shared host, it might be that other users are taking up too many connections.

Other problems to look out for is the use of persistent connections and running out of diskspace.

这篇关于php,mysql - 连接数据库错误太多的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆