Getting Error Too Many Connections In MySQL

Asked By 0 points N/A Posted on -
qa-featured

I am running a PHP/MySQL script on my laptop via localhost on XAMPP. I got an error too many connections code 1040. I cannot see the error in my script. I have configured the local host server correctly, and it is working fine with other PHP scripts. Please help.

Image result for error too many connections
SHARE
Answered By 0 points N/A #298100

Getting Error Too Many Connections In MySQL

qa-featured

There are two methods to solve your error.

  1. First of all, try the simpler method. Open you MySQL configurations file. You can find in the MySQL folder in XAMPP. Open this file using a suitable text editor. Once you open the file find a field named as ‘max_user_connection’ and set it to a high value.
  2. If this doesn’t work, make sure you have allotted enough bandwidth and disk space to the localhost. Open your task manager and make sure localhost is making optimum usage of allocated resources.
Answered By 590495 points N/A #326662

Getting Error Too Many Connections In MySQL

qa-featured

If you encountered error code “1040” with a message saying, “Too many connections” when trying to connect to a MySQL server, it means you have reached the maximum number of connections. It could also mean that all available allowed connections are currently in use by other clients and any of your attempts to connect will get rejected. The number of connections is defined by the system variable “max_connections”.

To allow more connections, you can set “max_connections” with a higher value. To see the existing value for “max_connections”, run the following command:

SHOW VARIABLES LIKE “max_connections”;

The default value is set to 151. But actually, MySQL allows up to “max_connections” + 1 which means the default setting is 151 + 1. The extra connection can be used by the user with a “SUPER” privilege only. To increase the value for “max_connections”, for example, 400, run this command:

SET GLOBAL max_connections = 400;

This command takes effect right after you execute it but only applies to the current session. If you want this setting to be permanent until you change it next time, you have to edit the “my.cnf” configuration file. It is normally located in “/etc/my.cnf”. To make the setting permanent, in “my.cnf” file, under “[mysqld]” section, you need to add the following line:

max_connections = 400

You have to restart the MySQL server for the new setting to take effect. There is no hard limit in setting the value for “max_connections” but increasing it will require more memory or RAM to run so increase it with caution. The maximum number can be estimated by the formula:

max.connection=(available RAM-global buffers)/thread buffers

Related Questions