1,2,4-Trimethoxybenzene (ZY16) is a natural compound identified as a selective nucleotide-binding oligomerization domain-like receptor protein 3 (NLRP3) inflammasome inhibitor. Studies have shown that NLRP3 inflammasome activation contributes significantly to the pathogenesis of diabetic cognitive impairment (DCD). Using a rat model of DCD induced by a high-carbohydrate and high-fat diet combined with streptozotocin (STZ), we evaluated the therapeutic effects of ZY16 and metformin on cognitive impairment in diabetic rats through the following measures: blood glucose levels, behavioral tests, biodiversity analysis of gut microbiota, and molecular and histological analyses. The results showed that ZY16 significantly reduced the area under the curve (AUC) of oral glucose tolerance and reduced glycated serum protein (GSP), insulin, and insulin resistance (IR) levels. It also ameliorated diabetes-related hyperlipidemia, lowered malondialdehyde (MDA) levels, and alleviated oxidative stress. In addition, it enhanced learning and memory abilities and improved neuropathy. Furthermore, ZY16 reduced the expression of NLRP3, apoptosis-associated speck-like protein (ASC), Gasdermin D (GSDMD), and Caspase-1. In addition, ZY16 reduced the levels of inflammatory factors such as Interleukin-1 beta (IL-1β), Interleukin-18 (IL-18) and Tumor necrosis factor-alpha (TNF-α) in the hippocampus of rats. Species richness, diversity, and composition of the rat gut microbiota was recovered. In conclusion, ZY16 plays a beneficial role in DCD by inhibiting NLRP3 inflammasome formation and restoring intestinal flora. This finding may contribute to the development of a novel intervention for the clinical management of DCD.