Titanium dioxide (TiO2) and silicon dioxide (SiO2) coating deposition were respectively performed by the dip coating technique on magnesium AZ31 alloy with extrusion surface finishes. The anticorrosive effect of different sol-gel coating was compared by measuring the weight loss when the samples were immerged in atmosphere, acetic acid aqueous solution with pH 5.0, distilled water with pH 6.4, aqueous 5% sodium chloride solution with pH 7.0. Morphological and structural characteristics of the coatings were analyzed by scanning electron microscopy (SEM), and semi quantitative analyses of the composition were performed by energy dispersive X-ray analysis (EDX) line scans. The results show that the anticorrosion properties of magnesium alloy with SiO2 or TiO2 are magnificently impactful in atmosphere. The anticorrosion effect of TiO2 coating is much preferable in a relatively strong acid environment.