The study focuses on the interaction between canonical uracil and its rare tautomers with Mg 2+ and MgCl 2 in the microcosmic water environment and aims to elucidate how ions interact with nucleobase and the cation−anion correlation effect involved using density functional theory calculations. The structures of the Ura− Mg 2+ (H 2 O) 0−6 and Ura−MgCl 2 (H 2 O) 0−6 clusters are characterized and show that the water molecules preferentially interact with Mg 2+ /MgCl 2 , and Mg 2+ adopts a hexacoordination pattern in both Ura− Mg 2+ (H 2 O) 0−6 and Ura−MgCl 2 (H 2 O) 0−6 clusters. When uracil interacts with Mg 2+ in (H 2 O) 0−6 environments, it tends to favor the formation of keto−enol structures. However, in the presence of Cl − cooperating with Mg 2+ , the Ura−MgCl 2 (H 2 O) 0−6 complexes prefer to form diketo structures. The proton transfer mechanism shows that the initial solvation can promote the change from the keto−enol structure to the diketo structure, which is strengthened by the analysis of the Ura−Mg 2+ (H 2 O) 6 and Ura−MgCl 2 (H 2 O) 6 structures in the aqueous phase using the PCM model. Additionally, reduced density gradient, atom in molecules, and energy decomposition analysis combined with charge transfer analysis were carried out to obtain the variation law of the interactions between Mg 2+ and Ura with the water number increasing, thereby revealing the interaction mechanism of uracil with magnesium ion and the effect of Cl − on the interaction between Mg 2+ and uracil.