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 ..
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.
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.
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.
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.
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
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!
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With