MySQL Too Many Connections Error Problem & Fix

If you are getting? Too many connections error when you try to open your website in browser, It means all available connection used by other script or mysql process. Number of connection to mysql server determined by setting in mysql conf? file.? By default,? it is 151? for MySQL 5.x and 100 for MySQL 4.x.? To change setting, open mysql conf file. In Linux it can be found (/etc/my.cnf) and in windows within installation folder. Find max_connections setting under [mysqld] section. This setting must be within [mysqld] section. Change setting which is suitable to you.

[mysqld]
max_connections=200

There are several reason that cause server to raise this error:

Persistent Connections: This is common cause of this error. If script uses persisit connection and script does? not close connection even if script terminates. To avoid this problem, try using mysql_connect() instead of mysql_pconnect(). Check this setting in third party script such as osCommerce. You can turn off this setting in php.ini file. Script using persist connection will use non-persistent connection without any warning or error if persistence connection disabled.

Server administrators can disable persistent connections for PHP scripts in php.ini file:

[MySQL]
; Allow or prevent persistent links.
mysql.allow_persistent=Off

Lower MySQL Connect Timeout: Check your mysql connect timeout setting. By default it is 60 seconds and php setting lowering below the dafault setting.

For example: following setting in .htaccess php_value mysql.connect_timeout 25

osCommerce? Setting:

The osCommerce setting mentioned by ?varo is in the catalog/includes/configure.php file:

define(‘USE_PCONNECT’, ‘false’); // use persistent connections?

It defaults to true, so mysql_pconnect() is used, and you get the error message “Warning: mysql_pconnect(): Too many connections …” Change to false for mysql_connect() to be used.

One thought on “MySQL Too Many Connections Error Problem & Fix”

  1. Good post and just a small update on your post after we increase the “max_connections” we need to restart our MYSQL server in order to reflect our changes.

Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>