If you don’t have enough connections open to your MySQL server, your users will begin to receive a “Too many connections” error while trying to use your service. To fix this, you can increase the maximum number of connections to the database that are allowed, but there are some things to take into consideration before simply ramping up this number.
Before you increase the connections limit, you will want to ensure that the machine on which the database is housed can handle the additional workload. The maximum number of connections that can be supported depends on the following variables:
Another issue to consider is that you may also need to increase the open files limit–This may be necessary so that enough handles are available.
To see what the current connection limit is, you can run the following from the MySQL command line or from many of the available MySQL tools such as phpMyAdmin:
This will display a nicely formatted result for you:
To increase the global number of connections temporarily, you can run the following from the command line:
If you want to make the increase permanent, you will need to edit the my.cnf configuration file. You will need to determine the location of this file for your operating system (Linux systems often store the file in the /etc folder, for example). Open this file add a line that includes max_connections, followed by an equal sign, followed by the number you want to use, as in the following example:
The next time you restart MySQL, the new setting will take effect and will remain in place unless or until this is changed again.
Instead of worrying about these settings on your own system, you could opt to use a service like Morpheus, which offers databases as a service on the cloud. With Morpheus, you can easily and quickly set up your choice of several databases (including MySQL, MongoDB, Redis, and Elasticsearch).
In addition, MySQL and Redis have automatic back ups, and each database instance is replicated, archived, and deployed on a high performance infrastructure with Solid State Drives. You can sign up for a free demo now to see how you can begin taking advantage of this service! Or, check out this 2-minute Morpheus Data intro video.