Mysql – Exclude IP from being blocked by MySQL

MySQL

I have a mysql server running. Due to the uptime is not perfect, sometimes the HTTP server is blocked when mysql server is down intermittently.

Host 'host_name' is blocked because of many connection errors.
Unblock with 'mysqladmin flush-hosts'

Currently, I have to set up a cron job to run "mysql-admin flush-hosts" to ensure my HTTP server can connect to database after the block.

My question is, how can I get certain IP (eg my HTTP Server) from being blocked by MySQL server ? Is it possible?

https://dev.mysql.com/doc/refman/5.0/en/blocked-host.html

Best Answer

I have a 4-year-old post on how to schedule FLUSH HOSTS:

In that old post, I mentioned two techniques

  • TECHNIQUE #1 : Use MySQL Event (See the event code from my old post)
  • TECHNIQUE #2 : Run perl script (See the perl code from my old post)
    • Setup Parameters to Heartbeat
    • Connect to the mysqld
    • Hold DB Connection open indefinitely
    • Run FLUSH HOSTS; on the set schedule

In either case, FLUSH HOSTS; can be executed regularly.

Notwithstanding, you should be polling status variables

SELECT * FROM information_schema.global_status
WHERE variable_name LIKE '%connect%';

to monitor connections attempts, dropped connections, and thing like these.