Objective: To investigate the role of YTHDF2 in cervical lesions and its potential molecular mechanism. Methods: Gene expression data of cervical tissue were obtained from the GEO database to analyze the expression of YTHDF2 mRNA and perform pathway enrichment analysis. Patients with cervical lesions diagnosed by thinprep cytologic test in Gynecological Outpatient Department of Maternal and Child Health Hospital in Jiexiu, Shanxi Province, were selected as the research subjects. Data of cervical lesions and cervical exfoliated cells were collected. HPV infection status was detected by flow-through hybridization, and the expression of YTHDF2 mRNA was detected by reverse transcription real-time polymerase chain reaction. The expression of YTHDF2 in cervical lesions and the mediating role of HPV infection in the relationship between YTHDF2 and squamous intraepithelial lesion (SIL) were evaluated. YTHDF2-related genes were screened from multiple datasets in the GEO and ENCORI databases, and their expression, immune infiltration, and survival analysis were performed to assess the association between YTHDF2 and prognosis. Results: Compared with normal cervical tissue, YTHDF2 was highly expressed in cervical lesion tissue (P<0.05). A total of 3 672 differentially expressed genes were screened from the dataset GSE49339. Gene Ontology analysis showed that YTHDF2 was mainly involved in transcription regulation. Kyoto Encyclopedia of Genes and Genomes analysis showed that YTHDF2 might be related to HPV infection and other signaling pathways. In the mediation analysis, χ2 test results showed that the expression level of YTHDF2 was significantly different among groups (χ2=22.47, P<0.001). Trend χ2 test further showed that the expression level of YTHDF2 was upregulated with the degree of cervical precancerous lesions (trend χ2=10.26, P=0.001). Multivariate logistic regression analysis indicated that high YTHDF2 expression increased the risk of low-grade squamous intraepithelial lesions (OR=3.15, 95%CI: 1.93-5.15) and high-grade squamous intraepithelial lesions (OR=1.85, 95%CI: 1.01-3.39). Mediation effect analysis revealed a partial mediating effect of HPV infection between YTHDF2 and SIL, accounting for 32.02% of the total effect. Twelve YTHDF2 related genes were screened by the intersection of multiple datasets. The immune infiltration analysis results showed that YTHDF2 and related genes KLF4, E2F3 and HOXC6 were associated with immune infiltration (all P<0.05). Multivariate Cox proportional hazard regression model analysis showed that low expression of KLF4 (HR=0.53, 95%CI: 0.30-0.94) and high expression of RHOB (HR=1.80, 95%CI: 1.04-3.13) were risk factors for the prognosis of cervical cancer. Conclusion: YTHDF2 is highly expressed in cervical lesions and may have been involved in the regulation of HPV infection-related pathways and its downstream related genes are related to immune infiltration and prognosis of cervical cancer, providing a theoretical basis for the study of mechanisms related to cervical lesions.