When there are many errors when connecting to a mysql server, the following error might appear and the application cannot connect to the db server any more:
Host 'yourhost' is blocked because of many connection errors; unblock with 'mysqladmin flush-hosts'
The above error might appear when the application server and db server are located in different servers. It also might happen quit frequently when we have db server locates in many nodes (such as replication, sharding, etc.).
How to fix it temporarily?
Of course, run
mysqladmin -u root -p'YourRootPassword' flush-hosts
on the target machine
How to fix it permanently?
Adjust the parameter max_connect_errors in the my.cnf file, and restart the mysqld service. E.g.
... max_connect_errors=4294967295 # 2^32 - 1 ...
We can also create a cron job to flush-hosts periodly 🙂