In this research, tartaric acid was used to enhance the hydroxyapatite coating on AZ31 Mg alloy substrate through post-treatment and direct addition methods, and the corrosion resistance and biological activity of the samples were investigated. The parameters of concentration, immersion time, and pH of the coating solution were optimized by Electrochemical Impedance Spectroscopy (EIS) and Direct Current (DC) Polarization techniques. According to EIS results in the post-treatment method, tartaric acid with a concentration of 1 g/L, pH = 9 and immersion time of 2 min, increased the corrosion resistance of hydroxyapatite coating from 3630 to about 18,763 S2.cm2. In the direct addition method, this value increased to 26,577 S2.cm2. The optimal sample obtained from this method has a concentration of 1 g/L of tartaric acid and an immersion time of 2 h. Further, the morphology, crystal structure, and chemical bonds on the surface were investigated via FE-SEM, XRD, and ATRFTIR analysis, respectively. Moreover, samples were immersed in SBF solution and after 3 weeks of immersion, the post-treatment sample exhibited the highest bio-corrosion resistance and the least morphological changes compared to other samples. Also, using antibacterial tests, it was concluded that the post-treatment method provides a coating with better antibacterial properties than other coatings.