To our knowledge, this is the first study to demonstrate that HEX plays a protective role in mastitis caused by dysbiosis and infection, thereby serving as a reference for the prevention of mastitis and other infectious and metabolic diseases. Here, HHEX is linked to mastitis.