Currently, there is limited understanding of the structures and variabilities of bacterial communities in oil-contaminated soil within shale gas development. The Changning shale gas well site in Sichuan province was focused, and high-throughput sequencing was used to investigate the structures of bacterial communities and functions of bacteria in soil with different degrees of oil pollution. Furthermore, the influences of the environmental factors including pH, moisture content, organic matter, total nitrogen, total phosphorus, oil, and the biological toxicity of the soil on the structures of bacterial communities were analyzed. The results revealed that Proteobacteria and Firmicutes predominated in the oil-contaminated soil. α-Proteobacteria and γ-Proteobacteria were the main classes under the Proteobacteria phylum. Bacilli was the main class in the Firmicutes phylum. Notably, more bacteria were only found in CN-5 which was the soil near the storage pond for abandoned drilling mud, including Marinobacter, Balneola, Novispirillum, Castellaniella, and Alishewanella. These bacteria exhibited resilience to higher toxicity and demonstrated proficiency in oil degradation. The functions including carbohydrate transport and metabolism, energy metabolism, replication, recombination and repair replication, signal transduction mechanisms, and amino acid transport and metabolism responded differently to varying concentrations of oil. The disparities in bacterial genus composition across samples stemmed from a complex play of pH, moisture content, organic matter, total nitrogen, total phosphorus, oil concentration, and biological toxicity. Notably, bacterial richness correlated positively with moisture content, while bacterial diversity showed a significant positive correlation with pH. Acidobacteria exhibited a significant positive correlation with moisture content. Litorivivens and Luteimonas displayed a significant negative correlation with pH, while Rhizobium exhibited a significant negative correlation with moisture content. Pseudomonas, Proteiniphilum, and Halomonas exhibited positive correlations not only with organic matter but also with oil concentration. Total nitrogen exhibited a significant positive correlation with Taonella and Sideroxydans. On the other hand, total phosphorus showed a significant negative correlation with Sphingomonas. Furthermore, Sphingomonas, Gp6, and Ramlibacter displayed significant negative correlations with biological toxicity. The differential functions exhibited no significant correlation with environmental factors but displayed a significant positive correlation with the Proteobacteria phylum. Aridibacter demonstrated a significant positive correlation with cell motility and cellular processes and signaling. Conversely, Pseudomonas, Proteiniphilum, and Halomonas were negatively correlated with differential functions, particularly in amino acid metabolism, carbohydrate metabolism, and membrane transport. Compared with previous research, more factors were considered in this research when studying structural changes in bacterial communities, such as physicochemical properties and biological toxicity of soil. In addition, the correlations of differential functions of communities with environmental factors, bacterial phyla, and genera were investigated.