An in situ Mg-Al hydrotalcite (LDH) film was prepared using a one-step hydrothermal method on the surface of a medical magnesium alloy. The importance and influence of the reaction parameters on the corrosion resistance of the LDH coatings were optimized and investigated through an orthogonal array and range analysis. The reaction parameters included the temperature, reaction time, pH, and concentration of the aluminum source. The relationship between the parameters and corrosion resistance performance of each coating was compared with the chemical composition, electrochemical corrosion current, and hydrogen evolution rate. Suitable reaction parameters were obtained. The morphology, element distribution, adhesion strength, and electrochemical properties of the preferred coatings were further analyzed and evaluated to optimize the treatment process. The results showed that temperature had the most significant impact on the quality of the LDH coating; a suitably high temperature, a longer reaction time, a higher aluminum source concentration, and a high pH were conducive to forming high-quality LDH coatings. There was an inverse relationship between the corrosion resistance and the LDH-to-Mg(OH)2 content ratio of the coatings. The optimal reaction parameters for this Mg-Al LDH coating on the substrate were 130 °C for 8 h at a pH of 13 using a 10 mM Al3+ solution.