The human body is home to a complex community of dynamic equilibrium microbiota, including bacteria, fungi, parasites, and viruses. It is known that the gut microbiome plays a crucial role in regulating innate and adaptive immune responses, intestinal peristalsis, intestinal barrier homeostasis, nutrient uptake, and fat distribution. The complex relationship between the host and microbiome suggests that when this relationship is out of balance, the microbiome may contribute to disease development. The brain–gut–microbial axis is composed of many signal molecules, gastrointestinal mucosal cells, the vagus nerve, and blood–brain barrier, which plays an essential role in developing many diseases. The microbiome can influence the central nervous system function through the brain–gut axis; the central nervous system can also affect the composition and partial functions of the gut microbiome in the same way. Different dietary patterns, specific dietary components, and functional dietary factors can significantly affect intestinal flora’s structure, composition, and function, thereby affecting human health. Based on the above, this paper reviewed the relationship between diet, intestinal flora, and human health, and the strategies to prevent mental illness through the dietary modification of intestinal microorganisms.