Biomedical titanium and its alloys have become the preferred materials for bone and joint implants due to their excellent biocompatibility, high specific strength, and low elastic modulus. However, poor biological activity and bacterial infection on the surface of titanium alloys have become major obstacles to their clinical application. Improving the osteogenic and antibacterial properties of titanium through surface modification is currently an important research area. In this study, a microporous magnesium-doped titanium dioxide coating was prepared on a titanium surface via microarc oxidation. This coating not only has a good porous surface morphology, with magnesium distributed on the surface of the coating, but also exhibits good resistance to corrosion and wear. In vitro cell experiments showed that the coating promoted proliferation, differentiation and mineralization in bone marrow mesenchymal stem cells, while bacterial experiments showed that the coating inhibited the growth of Staphylococcus aureus and Escherichia coli, with good antibacterial activity. This study provides a new theoretical and experimental basis for improving the biological activity of titanium.