亚洲 卡通 欧美 制服 中文,午夜在线看的免费网站,黑人太大了太深了好痛 视频,国产乱妇乱子视频在播放

廣州總部電話:020-85564311
20年
互聯(lián)網(wǎng)應(yīng)用服務(wù)商
廣州總部電話:020-85564311
20年
互聯(lián)網(wǎng)應(yīng)用服務(wù)商
請(qǐng)輸入搜索關(guān)鍵詞
知識(shí)庫 知識(shí)庫

優(yōu)網(wǎng)知識(shí)庫

探索行業(yè)前沿,共享知識(shí)寶庫

MySQL中performance_schema.host_cache表為空的原因

發(fā)布日期:2025-08-19 19:07:42 瀏覽次數(shù): 810 來源:DataBaseAholic
推薦語
MySQL性能監(jiān)控的關(guān)鍵表為何為空?一文帶你快速排查host_cache表無數(shù)據(jù)的原因。

核心內(nèi)容:
1. 檢查host_cache_size變量是否為0的關(guān)鍵步驟
2. host_cache_size參數(shù)對(duì)DNS查詢性能的影響機(jī)制
3. 動(dòng)態(tài)調(diào)整緩存大小的實(shí)時(shí)生效特性與最佳實(shí)踐
小優(yōu) 網(wǎng)站建設(shè)顧問
專業(yè)來源于二十年的積累,用心讓我們做到更好!

在MySQL数据库中,如果performance_schema.host_cache表中没有数据的话,需要从下面方面进行检查/排查

mysql> select count(*) from performance_schema.host_cache;
+----------+
| count(*) |
+----------+
|        0 |
+----------+
1 row in set (0.03 sec)

mysql>

1. 检查变量host_cache_size是否为0

mysql> show variables like '%host_cache_size%';
+-----------------+-------+
| Variable_name   | Value |
+-----------------+-------+
| host_cache_size | 663   |
+-----------------+-------+
1 row in set (0.00 sec)

mysql> 

当host_cache_size=0时, performance_schema将停止采集和存储host_cache表中的监控数据,导致performance_schema.host_cache表为空.

当前测试服务器的变量host_cache_size大小为663,host_cache_size 表示控制主机缓存的数量,设置为0时,禁用主机缓存,此时每次服务 器连接时,服务器都会进行DNS查找.另外, 此系统变量设置后立即生效,不用重启数据库服务器.

host_cache_size的官方文档介绍如下所示:

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.

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.

To disable DNS host name lookups, start the server with the skip_name_resolve system variable enabled. In this case, the server uses only IP addresses and not host names to match connecting hosts to rows in the MySQL grant tables. Only accounts specified in those tables using IP addresses can be used. (A client may not be able to connect if no account exists that specifies the client IP address.)

If you have a very slow DNS and many hosts, you might be able to improve performance either by enabling skip_name_resolve to disable DNS lookups, or by increasing the value of host_cache_size to make the host cache larger.

host_cache表提供对主机缓存内容的访问,其中包含客户机主机名和IP地址信息,用于避免DNS查找。

2. 检查变量skip_name_resolve

mysql> show variables like 'skip_name_resolve';
+-------------------+-------+
| Variable_name     | Value |
+-------------------+-------+
| skip_name_resolve | ON    |
+-------------------+-------+
1 row in set (0.00 sec)

mysql>

如上所示,系统变量skip_name_resolve=ON,那么连接MySQL数据库时不用DNS解析,此时它也不会向host_cache表写入数据. 另外,skip_name_resolve这个变量是一个只读变量,修改后需要重启MySQL实例才能生效.

系统变量skip_name_resolve:检查客户端连接时是否解析主机名,变量为off,则mysqld 会在检查客户端连接时解析主机名。 若变量为on,mysqld只使用 IP ;在这种情况下,授权表中的所有列值都必须是IP地址。

另外,在测试过程发现系统变量skip_name_resolve设置为OFF后,需要成功连接MySQL数据库后才会向host_cache写入数据,如果第一次就是使用 错误的密码连接访问数据库,此时host_cache表并不会写入一条数据.

注意:只有非本地主机的 TCP 连接会使用主机缓存;使用网络回环地址或 socket 建立的连接不会使用主机缓存. 所以测试验证的 时候请注意,否则你的实验结果可能会不一样.

其实,早期的MySQL版本,还有一个变量skip-host-cache,它的作用类似于host_cache_size,但mysql在运行时无法对该参数进行变更,并且 skip-host-cache在之后的版本中已弃用。当前测试版本为MySQL 8.0.38,无法测试,遂一笔带过.

3. 命令清空了host_cache

如果你或其他人执行了flush hosts命令, 它会刷新host_cache,刷新后会清除内存中的主机缓存. 不过这个是比较难排查的.

参考资料:

  1. https://dev.mysql.com/doc/refman/8.4/en/host-cache.html
  2. https://zhuanlan.zhihu.com/p/493702797

優(yōu)網(wǎng)科技,優(yōu)秀企業(yè)首選的互聯(lián)網(wǎng)供應(yīng)服務(wù)商

優(yōu)網(wǎng)科技秉承"專業(yè)團(tuán)隊(duì)、品質(zhì)服務(wù)" 的經(jīng)營理念,誠信務(wù)實(shí)的服務(wù)了近萬家客戶,成為眾多世界500強(qiáng)、集團(tuán)和上市公司的長期合作伙伴!

優(yōu)網(wǎng)科技成立于2001年,擅長網(wǎng)站建設(shè)、網(wǎng)站與各類業(yè)務(wù)系統(tǒng)深度整合,致力于提供完善的企業(yè)互聯(lián)網(wǎng)解決方案。優(yōu)網(wǎng)科技提供PC端網(wǎng)站建設(shè)(品牌展示型、官方門戶型、營銷商務(wù)型、電子商務(wù)型、信息門戶型、微信小程序定制開發(fā)、移動(dòng)端應(yīng)用(手機(jī)站APP開發(fā))、微信定制開發(fā)(微信官網(wǎng)、微信商城、企業(yè)微信)等一系列互聯(lián)網(wǎng)應(yīng)用服務(wù)。


我要投稿

姓名

文章鏈接

提交即表示你已閱讀并同意《個(gè)人信息保護(hù)聲明》

專屬顧問 專屬顧問
掃碼咨詢您的優(yōu)網(wǎng)專屬顧問!
專屬顧問
馬上咨詢
聯(lián)系專屬顧問
聯(lián)系專屬顧問
聯(lián)系專屬顧問
掃一掃馬上咨詢
掃一掃馬上咨詢

掃一掃馬上咨詢

和我們?cè)诰€交談!