Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

host 'X' Blocked because of many connection errors

Tags:

java

mysql

jsp

Hi I am Using Java with MySql . I have taken some x hosting service,in that i have deployed my java .war file it is worked some days ,since 2 days i am getting some error that is

java.sql.SQLException: null, message from server: "Host 'X host' is blocked because of many connection errors; unblock with 'mysqladmin flush-hosts'".

I used normal database connection as well as connection pooling.

My code is :

Class.forName("com.mysql.jdbc.Driver");
con = DriverManager.getConnection("jdbc:mysql://IP Address:3306/DBName?user=xxxxx&password=YYYYYYY");

..

Please Give a solution ..

like image 833
user1548560 Avatar asked Sep 28 '12 11:09

user1548560


People also ask

Is blocked because of many connection errors unblock with?

Host is blocked because of many connection errors. Unblock with mysqladmin flush hosts" is a database side error and occurs due to multiple connections created while connecting the database. To resolve the above error, you need to execute "Flush hosts " command. You can execute the command as per below syntax.

What does Mysqladmin flush hosts do?

In the case of FLUSH HOSTS; , MySQL will empty the host cache, which effectively means MySQL's record of which hosts are currently or have recently connected is reset, allowing for further connections from said hosts.

Why does MySQL have so many connections?

Solve a MySQL/MariaDB "Too many connections" error. The MySQL “Too many connections” error occurs when more queries are sent to a MySQL database than can be processed. The error can be fixed by setting a new number of maximum connections in the configuration file or globally.

What is Max_connect_errors?

MySQL has a parameter called max_connect_errors to prevent user from connecting to the database if they make too many connection errors (e.g. from wrong password) for security reason. The default for this value is 10.


2 Answers

Unblocking the host with 'mysqladmin flush-hosts' Or Increasing the max_connect_errors parameter will solve the problem .

server startup:

shell> mysqld_safe --max_connect_errors=10000 &

Runtime:

mysql> SET GLOBAL max_connect_errors=10000;

But the cause for connection error should be identified. It Can be Identified by * Checking MySQL.err log file * Checking TCP/IP connection parameters in the host

Reference: http://dev.mysql.com/doc/refman/5.0/en/blocked-host.html http://dev.mysql.com/doc/refman/5.0/en/server-system-variables.html#sysvar_max_connect_errors

like image 93
Ashok Avatar answered Sep 18 '22 20:09

Ashok


To recover the system you might have to restart the mysql server.

$ sudo service mysql restart

To stop happening this again, Before restarting increase below values,

$ mysql> SET GLOBAL max_connections = 500;
$ mysql> SET GLOBAL max_connect_errors=10000;

To see the current value please go through the my.cnf

$ vi /etc/mysql/my.cnf

Hope this helps!

like image 20
tk_ Avatar answered Sep 19 '22 20:09

tk_