Objective: Comprehensive bioinformatics methods were used to explore the immune-related genes and immune changes in myocardial infarction and to validate the immune-related genes.Methods: Gene expression data came from three datasets, GSE29111, GSE66360 and GSE48060. GSE29111 and GSE66360 were combined as training set and GSE48060 as the validation set. Differential gene, GO/KEGG enrichment, PPI, WCGNA, GSEA, and immune infiltration analyses were performed to find immune-related core genes for myocardial infarction. Diagnostic ability of core genes was assessed by ROC curves. RT-PCR was used to verify differences in expression of core genes between myocardial infarction and control patients. One of the immune-related core genes, BCL6, was selected for further study. The relationship between BCL6 and inflammatory response and oxidative stress was explored by detecting the inflammatory factors TNF-α, IL-1, IL-6, NADPH oxidase subunits p67 and gp91, SOD activity and MDA content.Results: The differential analysis identified 91 differential genes. GO and KEGG enrichment analysis involved response to lipopolysaccharide, IL-17 signaling pathway. Among the PPI network constructed by 91 differential genes, four core genes were identified. WCGNA analysis was performed and 13 core genes were identified. The final core genes obtained after taking the intersection were S100A12, BCL6. We verified the diagnostic ability of them, and the expression of them was significantly different between two groups(P<0.01) with AUCs of 0.809 (95% CI 0.733-0.874), 0.837 (95% CI 0.771-0.896). The diagnostic ability in the validation set was equally favorable, with AUCs of 0.789 (95% CI 0.662-0.908) and 0.733 (95% CI 0.573-0.866). The results of immune infiltration and correlation analysis showed a significant positive correlation between two core genes and immune cells. RT-PCR results showed a significant difference in the expression of S100A12 and BCL6 between two groups (P<0.001). The expression of the inflammatory factors were higher in the infarct group than in the control group after BCL6 knockdown (P<0.01), indicating that BCL6 knockdown exacerbated the inflammatory response. Similarly, the expression levels of NADPH oxidase subunits and MDA content were significantly higher in BCL6 knockdown than in the control group (P<0.01), and SOD activity was significantly lower than in the control group (P<0.01), indicating that BCL6 knockdown exacerbated the level of oxidative stress. Conclusion: S100A12 and BCL6 may serve as candidate biomarkers for early detection of myocardial infarction and have promise as new therapeutic targets.