The server handles entries in the host cache like this: 

1. When the first TCP client connection reaches the server from a given IP address, a new cache entry is created to record the client IP, host name, and client lookup validation flag. Initially, the host name is set to NULL  and the flag is false. This entry is also used for subsequent client TCP connections from the same originating IP. 

2. If the validation flag for the client IP entry is false, the server attempts an IP-to-host name-to-IP DNS resolution. If that is successful, the host name is updated with the resolved host name and the validation flag is set to true. If resolution is unsuccessful, the action taken depends on whether the error is permanent or transient. For permanent failures, the host name remains NULL  and the validation flag is set to true. For transient failures, the host name and validation flag remain unchanged. (In this case, another DNS resolution attempt occurs the next time a client connects from this IP.) 

3. If an error occurs while processing an incoming client connection from a given IP address, the server updates the corresponding error counters in the entry for that IP. For a description of the errors recorded, see Section 27.12.21.2, “The host_cache Table” . 

To unblock blocked hosts, flush the host cache; see Dealing with Blocked Hosts. 

It is possible for a blocked host to become unblocked even without flushing the host cache if activity from other hosts occurs: 

•If the cache is full when a connection arrives from a client IP not in the cache, the server discards the least recently used cache entry to make room for the new entry. 

•If the discarded entry is for a blocked host, that host becomes unblocked. 

Some connection errors are not associated with TCP connections, occur very early in the connection process (even before an IP address is known), or are not specific to any particular IP address (such as out- of-memory conditions). For information about these errors, check the Connection_errors_ xxx  status variables (see Section 5.1.10, “Server Status Variables” ). 

## Configuring the Host Cache 

The host cache is enabled by default. The host_cache_size  system variable controls its size, as well as the size of the Performance Schema host_cache  table that exposes the cache contents. The cache size can be set at server startup and changed at runtime. For example, to set the size to 100 at startup, put these lines in the server my.cnf  file: 

[mysqld] host_cache_size=200 

To change the size to 300 at runtime, do this: 

SET GLOBAL host_cache_size=300; 

Setting host_cache_size  to 0, either at server startup or at runtime, disables the host cache. With the cache disabled, the server performs a DNS lookup every time a client connects. 

Changing the cache size at runtime causes an implicit host cache flushing operation that clears the host cache, truncates the host_cache  table, and unblocks any blocked hosts; see Flushing the Host Cache. 

Using the --skip-host-cache  option is similar to setting the host_cache_size  system variable to 0, but host_cache_size  is more flexible because it can also be used to resize, enable, and disable the host cache at runtime, not just at server startup. Starting the server with --skip-host-cache  does not 

