The mechanism of the difference in bacterial community composition caused by environmental factors in the underground coal mine is unclear. In order to reveal the influence of coal mining activities on the characteristics of bacterial community structure in coal seam, 16S rRNA gene amplicon sequencing technology was used to determine the species abundance, biodiversity, and gene abundance of bacterial community in a coal mine in Shanxi Province, and the environmental factors such as metal elements, non-metal elements, pH value, and gas concentration of coal samples were determined. The results showed that environmental factors and bacterial communities had obvious regional characteristics. Mining activities greatly affected the α diversity of bacterial communities, mining working face > main airway > roadway roof > unexposed coal seam > tunneling roadway. The bacterial community composition of each sample point is also very different. The main airway, roadway roof, and unexposed coal seam are dominated by Actinobacteria while the mining working face and tunneling roadway are dominated by Proteobacteria. Among the gene abundances of metabolic pathways in each site, Citrate cycle had the greatest difference, followed by glycine, serine and threonine metabolism, and oxidative phosphorylation and methane metabolism had little difference. RDA analysis showed that the environmental factors affecting the bacterial community were mainly cadmium, oxygen, hydrogen, and gas content. CCA analysis divided the bacterial community into three categories. Degradation functional bacteria are located in mining working face, bacteria that tolerate poor environments are located in main airway and tunneling roadway, and human pathogens are mostly located in roadway roof and unexposed coal seam. The research results would provide support for realizing green and safe mining in coal mines.