How to Prevent Blocked Host Connection from Many Connection Errors in MySQL
- By : Mydatahack
- Category : DBA, Infrastructure
- Tags: Configuration, Error Handling, MySQL
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. In case of AWS RDS, I don’t think the value is set. Therefore, when you are trying to connect to MySQL without changing this parameter, you will get the error message below.
Host ‘
It also has a similar parameter called max_error_count. If a user makes more errors than this value, they will be blocked and get the same host blocked error.
The solution to prevent this error from happening is simple. Increase max_connect_errors and max_error_count.
First of all, you can check these variables with SQL commands
1 2 | SHOW VARIABLES LIKE 'max_connect_errors'; SHOW VARIABLES LIKE 'max_error_count'; |
You can increase the value
1 2 | SET Global max_connect_errors=100000; SET Global max_error_count=10000; |
In AWS RDS, you can manually edit the parameter group for the instance. This is especially useful when you get the error and locked out from accessing the database as you do not have the direct host access for RDS.