Magnesium-substituted hydroxyapatite coatings have been deposited on magnesium alloy for biomedical applications by sol–gel technology. The Ca(10−x)Mgx(PO4)6(OH)2 coatings obtained, with magnesium contents up to x = 1.5, show dense and compact and with visible cracks. The results of Hydrogen (H2) evolution testing in Hank’s solution show that magnesium-substituted hydroxyapatite coatings can improve the corrosion resistance of magnesium alloy.