Microbially induced carbonate precipitation (MICP) is a new foundation treatment technology, which can improve the mechanical properties of soil. In this study, sand specimens containing different magnesium/calcium ion concentration ratios (Mg2+/Ca2+=0/0.5, 0.1/0.4, 0.2/0.3, 0.25/0.25, 0.4/0.1, and 0.5/0) were selected. Moreover, the effects of magnesium ions on the mechanical properties and mechanism of the biocemented sand were explored by oedometer tests, unconfined compressive strength tests, cyclic triaxial tests, scanning electron microscopy (SEM), and X-ray diffraction (XRD). The results showed that when the Mg2+ concentration is low, with increasing Mg2+/Ca2+, the compressibility of the biocemented sand decreases, the unconfined compressive strength increases, and the antiliquefaction performance improves. When Mg2+/Ca2+=0.2/0.3, the sand specimen showed the worst compressibility and the best unconfined compressive strength and antiliquefaction performance. When the Mg2+ concentration was high, all the mechanical properties of the specimen were weakened. Low Mg2+ concentrations promote the formation of aragonite, whereas high Mg2+ concentrations promote the formation of dolomite. In addition, the SEM and XRD results verified the effect of Mg2+ on the crystal morphology and composition. This study showed that low Mg2+ concentrations can be added to improve the mechanical properties of the sand specimen and achieve a better reinforcement effect when using MICP to consolidate the soil.