MySQL Variables host_cache_size 数据库 参数变量解释及正确配置使用
本站中文解释
host_cache_size参数控制MySQL实例使用的主机缓存的大小。这将影响MySQL实例显示的计算能力。该参数主要用于存储引擎,特别是MyISAM。
设置此参数的大小可能会影响MySQL实例的性能,取决于需要缓存多少内存。如果希望MySQL实例能够充分利用内存,并最大程度地提高性能,请尽可能设置host_cache_size参数的大小。
要设置host_cache_size参数,可以使用MySQL命令行客户端(及其他客户端),或者使用MySQL管理工具,如phpMyAdmin。例如,使用MySQL 命令行客户端,你可以输入“SET GLOBAL host_cache_size=100;”来设置host_cache_size参数的大小为100Mb。
官方英文解释
host_cache_size
Command-Line Format | --host-cache-size=# |
---|---|
System Variable | host_cache_size |
Scope | Global |
Dynamic | Yes |
Type | Integer |
Default Value | -1 (signifies autosizing; do not assign this literal value) |
Minimum Value | 0 |
Maximum Value | 65536 |
The MySQL server maintains an in-memory host cache that
contains client host name and IP address information and is
used to avoid Domain Name System (DNS) lookups; see
Section 5.1.11.2, “DNS Lookups and the Host Cache”.
The host_cache_size
variable
controls the size of the host cache, as well as the size of
the Performance Schema host_cache
table that exposes the cache contents. Setting
host_cache_size
has these
effects:
-
Setting the size to 0 disables the host cache. With the
cache disabled, the server performs a DNS lookup every
time a client connects. -
Changing the size at runtime causes an implicit host cache
flushing operation that clears the host cache, truncates
thehost_cache
table, and
unblocks any blocked hosts.
The default value is autosized to 128, plus 1 for a value of
max_connections
up to 500,
plus 1 for every increment of 20 over 500 in the
max_connections
value, capped
to a limit of 2000.
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
prevent runtime changes to the value of
host_cache_size
, but such changes have no
effect and the cache is not re-enabled even if
host_cache_size
is set larger than 0.
Setting the host_cache_size
system variable
rather than the
--skip-host-cache
option is
preferred for the reasons given in the previous paragraph. In
addition, the --skip-host-cache
option is
deprecated in MySQL 8.0, and its removal is expected in a
future version of MySQL.