Background. Qiweibaizhu decoction (QBD), a classic Chinese herbal formula, has been widely used for treating diarrhea in infants and children with spleen deficiency syndrome for centuries, but its mechanism of action remains unclear. The gut microbiota, short-chain fatty acids (SCFAs), and intestinal mucus are closely associated with diarrhea. Methods. In this study, the composition of the gut microbiota in diarrheal rats was analyzed by 16S rDNA amplicon sequencing. The concentrations of colon SCFAs were determined using gas chromatography-mass spectrometry (GC-MS). The expression of mucin 2 (MUC2) in the colon was detected by immunofluorescence. Results. Diarrhea significantly changed the diversity and structure of the gut microbiota and disrupted the mucus barrier in juvenile rats. QBD did not significantly change the diversity and structure of the intestinal flora, but it enhanced the increasing tendencies of Verrucomicrobia and Akkermansia and decreased the abundance of Turicibacter (
P
=
0.037
) and Flavonifractor (
P
=
0.043
). QBD tends to repair the mucus layer and promote MUC2 expression in juvenile rats with diarrhea. Moreover, S. boulardii significantly increased the abundance of Parasutterella (
P
=
0.043
). In addition, QBD treatment tends to increase the propionic acid concentration during diarrhea, but its levels of acetic acid, propionic acid, butyric acid, and total SCFAs were lower than those in the S. boulardii group. Conclusion. S. boulardii significantly increased the abundance of Parasutterella, leading to increased production of acetic acid, propionic acid, and butyric acid, consequently leading to alleviation of diarrhea. In comparison, QBD affected diarrhea via regulation of the intestinal flora, especially by increasing the abundance of Verrucomicrobia and Akkermansia, resulting in mucus barrier repair, protection of the intestines, and treatment of diarrhea.