In this study, a hydrothermal method was employed to cultivate Mg(OH)2 precursor layers on the surface of AZ31 magnesium alloy samples. Subsequently, Mg-Al LDHs films were successfully synthesized through an in-situ growth approach. The phase composition of the films were analyzed using X-ray diffraction and infrared spectroscopy. The growth process and surface morphology of the films at the microstructure level were examined and interpreted using scanning electron microscopy and EDS. The corrosion resistance of the films was assessed through potentiodynamic polarization curves, electrochemical impedance spectroscopy, and hydrogen evolution tests. The findings indicate that the Mg(OH)2 precursor effectively mitigates defects in the Mg-Al LDHs films and improves the LDHs microstructure. Moreover, the precursor synthesized at a pH range of 10 to 12 better enhances the corrosion resistance of the Mg-Al LDHs film.