A MySQL server has a finite number of connections that it will allow, which acts as a safety mechanism against potentially harmful actions. During usual interaction with the server a script will make a connection, run its query and return the query results. The script should also disconnect from the MySQL server when it’s finished to free up one of the limited number of connections that the server will allow. Not doing so can eventually cause an overflow error, which will often not manifest itself until much later in the development process or worse still after client delivery.
How to rectify a MySQL error 1129 ‘Too many hosts’ overflow.
Assuming that your MySQL server is not being maliciously attacked a simple command entered at the command line is enough to flush the hosts cache. If you do not have access to the command line then you will need to get an Admin at your webhost to execute this for your. The command is:
mysqladmin flush-hosts
Once you have flushed your MySQL server should take off its tin hat and step out of the bunker; metaphorically speaking anyway. Again assuming that you have a hosts cache overflow through some result other than a malicious testing the system, you are going to need to fix whatever caused the problem so it doesn’t keep occurring.
Best Practice for disconnecting from the MySQL server
One way of insuring that you disconnect from the MySQL server on every occasion is to add a small script to the footer element of your page (If your site is too small to need you to include or require a footer then you can just add this to each page by hand). The code itself is very basic PHP but means you can eliminate your pages causing any host errors and rest assured you have disconnected from the MySQL server too.
<?php
if(isset($my_db_connection)){
mysql_close($my_db_connection);
}
?>
Where you have originally connected to the database using something resembling:
$my_db_connection = mysql_connect(DB_SERVER,DB_USER,DB_PASS);