HostOnNet Blog

Host X is blocked because of many connection errors; unblock with ‘mysqladmin flush-hosts’

Looking for Linux Server Admin or WordPress Expert? We can help.

I got following error in a PHP Application

Warning: mysql_connect() [function.mysql-connect]: Host 'server10.hosthat.com' is blocked because of many connection errors; unblock with 'mysqladmin flush-hosts' in /home/hon/public_html/cp/admin/approve.php on line 6
Unable to connect to mysql server

This is because MySQL server blocked remote server due to connection errors.

Default max_connect_errors value is 10, that is remote host will be blocked if there is more than 10 connection errors.

To fix, run

mysqladmin flush-hosts

on server running MySQL server.

To avoid this happening again, edit my.cnf

vi /etc/my.cnf

Add

set-variable = max_connect_errors=5000

below

[mysqld]

Example my.cnf

[root@server12 ~]# cat /etc/my.cnf
[mysqld]
datadir=/backup/mysql
socket=/var/lib/mysql/mysql.sock
user=mysql
set-variable = max_connections=500
set-variable = max_connect_errors=5000
old_passwords=1
safe-show-database
skip-locking
skip-innodb
max_allowed_packet = 1M
set-variable = table_cache=1024
set-variable = query_cache_type=1
set-variable = query_cache_limit=1M
set-variable = query_cache_size=128M ## 32MB for every 1GB of RAM

[mysqld_safe]
log-error=/var/log/mysqld.log
pid-file=/var/run/mysqld/mysqld.pid

[mysql]
socket=/var/lib/mysql/mysql.sock

[mysqladmin]
socket=/var/lib/mysql/mysql.sock

[mysqldump]
socket=/var/lib/mysql/mysql.sock

[root@server12 ~]#

Posted in MySQL

Leave a Reply

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

This site uses Akismet to reduce spam. Learn how your comment data is processed.