Last updated on August 4th, 2022 at 08:27 am

If you get a Too many connections error when you try to connect to the MySQL server, then it clearly means that all available connections are in use.
Too Many Connections can be caused by either a lot of simultaneous connections or by old connections not being released properly.
Factors affecting the connection of MySQL
1)mysql_pconnect()
2)mysql_connect()
3)mysqladmin flush-hosts

Along with these parameters you can also check the existing process list run this command as root

 mysqladmin -u <user> -p<password> processlist

mysql_pconnect(), This creates a permanent connection to the database (permanent is defined as 8 hours by the MySQL wait_timeout system variable). It will only create a new connection if it cannot find an existing permanent connection to reuse. You need to be careful with mysql_pconnect() to make sure that you don’t run out of connections, since these stay open so long and you cannot close them with mysql_close().

mysql_connect(), This can be better than mysql_pconnect() because these connections can be short lived, and can be closed when needed with mysql_close(). An important parameter is the CLIENT_INTERACTIVE flag. If this is passed, it will use the MySQL interactive_timeout value instead of wait_timeout. Since wait_timeout defaults to 8 hours, this seems like a great idea. However, surprisingly interactive_timeout also defaults to 8 hours. You should change this value to something smaller that fits your system.

mysqladmin flush-hosts, That command drops dead connections.

You can also use this command when you experience these type of errors
Host ‘host_name’ is blocked because of many connection errors.
Unblock with ‘mysqladmin flush-hosts’

Solution:

As root, run the command:

mysqladmin flush-hosts

Leave a Reply

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