Provided are a coating capable of improving the surface corrosion resistance and biocompatibility of medical magnesium and magnesium alloys and a preparation method therefor. In the present invention, an electrolyte is composed of an aqueous solution containing a Zn2+ salt, a Ca2+ salt, a H2PO4 - salt and NaNO3. A zinc-calcium-phosphate-containing coating with good coverage is prepared on the surfaces of magnesium and a magnesium alloy with the electrolyte through an electrochemical deposition method. The coating of the present invention falls within non-stoichiometric CaZn2(PO4)2·2H2O coatings, and is mainly applied to medical magnesium and magnesium alloys, especially for the surface treatment of a magnesium alloy for bone implant materials. The significant advantages thereof are that degradation can be achieved while the corrosion resistance of a magnesium matrix is improved, and the presence of the coating does not change the degradability of the matrix. At the same time, Zn2+ can be released during the