Major histocompatibility complex (MHC) is an important complex that presents antigen to T cells. The second exon of swine MHC (SLA) class II genes has antigen binding sites that bind with extracellular antigen. Populations with high MHC gene diversity result in low gut microbiota, and individuals with MHC gene heterozygote have lower gut microbiota diversity than that of homozygote. The pig is an animal with organs physiologically and anatomically similar to humans than any other mammal, and the pig is also suitably developed as a laboratory animal to establish the animal models of human disease. However, the relationship between SLA genetic diversity and the gut microbes of the pig is ambiguous. We studied the characterization of SLA class II genes and calculated the genetic diversity, and then we selected experimental animal groups divided by different SLA genotypes to investigate the gut microbiota composition by sequencing V3 to V4 hypervariable regions of bacterial 16 s rRNA from fecal samples. Our results showed that Guizhou minipigs had a low SLA genetic diversity, which may be due to the small founder population. The Guizhou minipig population deviated from neutral selection and balancing selection, which shows that Guizhou minipigs experience a strong artificial selection in recent years. We observed that the sex differences influenced gut microbiota much more deeply than that of genetics. Our results also showed that the individual with heterozygote of genes at the SLA class II region had much higher abundant gut microbiota than that of the homozygote.