The pathogenesis of type 2 diabetes mellitus (T2DM) is commonly associated with altered gut bacteria. However, whether the microbial dysbiosis that exists in human diabetic patients with or without retinopathy is different remains largely unknown. Here, we collected clinical information and fecal samples from 75 participants, including 25 diabetic patients without retinopathy (DM), 25 diabetic patients with retinopathy (DR), and 25 healthy controls (HC). The gut microbial composition in the three groups was analyzed using 16S ribosomal RNA (rRNA) gene sequencing. Microbial structure and composition differed in the three groups. The α and β diversities in both the DM and DR groups were reduced compared with those in the HC group. Blautia was the most abundant genus, especially in the DM group. In addition, increased levels of Bifidobacterium and Lactobacillus and decreased levels of Escherichia-Shigella, Faecalibacterium, Eubacterium_hallii_group and Clostridium genera were observed in the DM and DR groups compared with the HC group. Furthermore, a biomarker set of 25 bacterial families, which could distinguish patients in the DR group from those in the DM and HC groups was identified, with the area under the curve values ranging from 0.69 to 0.85. Of note, Pasteurellaceae, which was increased in DM and decreased in DR compared with HC, generated a high AUC (0.74) as an individual predictive biomarker. Moreover, 14 family biomarkers were associated with fasting blood glucose levels or diabetes, with most of them being negatively correlated. In summary, our study establishes compositional alterations of gut microbiota in DM and DR, suggesting the potential use of gut microbiota as a non-invasive biomarker for clinical and differential diagnosis, as well as identifying potential therapeutic targets of diabetic retinopathy.