Well-crystallized MgZnO alloy thin films with hexagonal wurtzite structure were fabricated by sol-gel method. With the band gap increases, the surface roughness and the grain size reduces. It is worth noting that the intensity of the band-edge luminescence of Mg doped films enhances with the increase of the Mg content. The microstructure and photoluminescence mechanism have been discussed based on X-ray diffraction patterns, atomic force microscopy images, ultraviolet-visible absorption spectra, photoluminescence spectra and Fourier transform infrared spectra.