Gut microbiota and childhood maltreatment are closely related to depressive symptoms. This study aimed to analyze the characteristics of gut microbiota in major depressive disorder (MDD) patients with childhood maltreatment experience and explore the correlation between gut microbiota, childhood maltreatment, and depressive symptoms. A total of 37 healthy controls (HCs) and 53 patients with MDD were enrolled, including 18 MDD patients without childhood maltreatment experience and 35 MDD patients with childhood maltreatment experience. The Hamilton’s Depression Scale (HAMD-24) and Childhood Trauma Questionnaire-Short Form (CTQ-SF) were used to evaluate their depressive symptoms and childhood maltreatment experience, respectively. The composition of gut microbiota was evaluated using 16S rRNA sequencing. Spearman’s correlation analysis was used to evaluate the correlation between different gut microbiota, depressive symptoms and childhood maltreatment. The mediation analysis was used to evaluate the mediating effect of gut microbiota. In the α-diversity analysis, we found that the Simpson index and Pielou’s Evenness index differed significantly between MDD patients without childhood maltreatment experience and HCs. In the β-diversity analysis, principal coordinate analysis (PCoA) showed significant differences between MDD patients without childhood maltreatment experience, MDD patients with childhood maltreatment experience and HCs. Twenty-seven different bacteria were identified through Linear discriminant analysis effect size (LEfSe) analysis at different levels of classification. The analysis of the correlation showed that Blautia, Bifidobacterium, Bacteroides, Roseburia, and Phascolarctobacterium were significantly correlated with HAMD and CTQ-SF scores. The mediation analysis showed that childhood maltreatment had a significant direct effect on the patients’ depressive symptoms, and Blautia, Bifidobacterium, Roseburia had a significant mediating effect. The findings of this study suggested that MDD patients with childhood maltreatment experience had different gut microbiota, which might have a mediating effect on the influence of childhood maltreatment on depressive symptoms.