Vacuum thermal diffusion technique was applied to preparing alloying coating on AZ31 B magnesium alloy. The microstructure and phase composition of the coatings prepared at different holding time were investigated in detail using optical microscopy(OM), scanning electron microscopy(SEM), energy dispersive spectrometer(EDS) and X-ray diffraction(XRD), and so on. The microhardness tester and electrochemical workstation(PS-168a) were used to measure the microhardness and corrosion resistance of the alloying coating. The results showed that the alloying coatings gradually generated with the extension of holding time under constant temperature. And the obvious bonding interface between the coating and substrate was observed, and the bonding interface was changed from smooth to zigzag. EDS and XRD analyses showed that the microstructure of alloying coating mainly consisted of eutectic α-Mg phase and continuous network β-Al(12)Mg(17) phase. The average microhardness of the coatings increased by 113% in comparison to the substrate, and the self-corrosion potential increased from-1.389 to-1.268 V at the same time.