TheRobotLearns Platform · ProxySQL: from first install to production
Ban Abusive Client Hosts with Client Error Limits
Learning objectives
- Explain client error limit rejection of addresses exceeding the configured threshold.
- Use mysql-client_host_error_counts and mysql-client_host_cache_size to set rejection limits and cache size.
- Trace client host cache lifecycle from failed attempts to rejection and successful-clear.
- Clear cached client host state using PROXYSQL FLUSH MYSQL CLIENT HOSTS.
- Read and reset host cache counters using stats_mysql_client_host_cache and stats_mysql_client_host_cache_reset.
Rejection from problematic client addresses
A failing client host keeps opening connection attempts that do not succeed. The Client Error Limit feature restricts connection attempts from addresses that exceed a specified error threshold. It prevents future connections from problematic sources.
When a new connection arrives, the cache checks if the client address has reached the maximum error count. If exceeded, ProxySQL logs an error and rejects the connection. If the address has not exceeded the limit, the connection attempt proceeds.
A failed attempt causes the address to be added to the cache, or its error count incremented. A successful attempt removes the address from the cache if it was previously present.
mysql-client_host_error_counts and mysql-client_host_cache_size control this behavior. mysql-client_host_error_counts sets the maximum allowable errors before an address is banned from new connections. mysql-client_host_cache_size defines cache capacity for tracking client addresses with connection errors.
Both variables default to 0, which disables the feature. Enable it by setting mysql-client_host_cache_size above zero. PROXYSQL FLUSH MYSQL CLIENT HOSTS clears the client host cache entirely.
stats_mysql_client_host_cache and stats_mysql_client_host_cache_reset let you read host cache counters. Querying the reset table also resets the counters.
Takeaway: The Client Error Limit rejects new connections from addresses that exceed the configured error threshold.
Cache size and error limits
You track client addresses with connection errors in a cache. mysql-client_host_cache_size defines cache capacity for tracking those addresses. mysql-client_host_error_counts sets the maximum allowable errors before an address is banned from new connections. Both default to 0, and 0 disables the feature. Enable it by setting mysql-client_host_cache_size above zero.
When a failed connection attempt happens, the address is added to the cache, or its error count is incremented. If the cache is full, the oldest entry is replaced. This replacement follows the cache capacity set by mysql-client_host_cache_size.
When a successful connection attempt happens, the address is removed from the cache if it was previously present. That means the address is no longer in the cache. Rejection still depends on mysql-client_host_error_counts, because the cache checks whether an address has reached the maximum error count when a new connection arrives.
Takeaway: mysql-client_host_cache_size sets how many client addresses the cache can track, and mysql-client_host_error_counts sets the rejection threshold.
Monitoring and clearing cache
You can inspect the cached client host counters with stats_mysql_client_host_cache. This table lets you read host cache counters. The cache can become full, and the oldest entry is replaced. If you need to clear cached client host state entirely, run PROXYSQL FLUSH MYSQL CLIENT HOSTS. That command clears the client host cache. When you want to reset the counters after reviewing them, query stats_mysql_client_host_cache_reset. Querying this table also resets the counters.
After a failed attempt, the address is added to the cache, or its error count is incremented. After a successful attempt, the address is removed from the cache if present. If the limit is exceeded, the connection is rejected. The cache size defines capacity for client addresses with connection errors. You read the current counters with stats_mysql_client_host_cache. You reset counters with stats_mysql_client_host_cache_reset. Use PROXYSQL FLUSH MYSQL CLIENT HOSTS to clear the cache instead.
Querying stats_mysql_client_host_cache_reset resets counters. The flush command clears the client host cache entirely. A successful connection removes an address from the cache if it was previously present. The maximum error count controls when a new connection from an address is rejected. The error count sets the maximum allowable errors before an address is banned from new connections.
Takeaway: Use stats_mysql_client_host_cache to read counters, stats_mysql_client_host_cache_reset to reset counters, and PROXYSQL FLUSH MYSQL CLIENT HOSTS to clear the cache.
Inspect, reset, and clear host cache state
-- The feature is enabled when mysql-client_host_cache_size is above zero.
-- mysql-client_host_error_counts sets the maximum allowable errors before an address is banned from new connections.
SELECT * FROM stats.stats_mysql_client_host_cache;
SELECT * FROM stats.stats_mysql_client_host_cache_reset;
PROXYSQL FLUSH MYSQL CLIENT HOSTS;This block names the two variables, then reads counters, resets counters, and clears the cache. The first comment says mysql-client_host_cache_size above zero enables the feature. The second comment says mysql-client_host_error_counts sets the maximum allowable errors before an address is banned from new connections. The first SELECT reads counters from stats_mysql_client_host_cache. The second SELECT queries stats_mysql_client_host_cache_reset; that query also resets the counters. PROXYSQL FLUSH MYSQL CLIENT HOSTS clears the client host cache entirely.
Sources
Do more with an account
- Graded quizzes is available on your account.
- Saving your progress is available on your account.
- Hands-on labs is available on your account.
- AI tutoring is available on your account.