The invention provides a ZnMgO ultraviolet detector and a preparation method thereof, and the method comprises the steps: S1, taking an organic zinc compound as a zinc source, taking an organic magnesium compound as a magnesium source, taking high-purity oxygen as an oxygen source, and growing a ZnMgO film on the surface of a substrate by adopting a metal organic compound chemical vapor depositionmethod; S2, forming an interdigital electrode mask on the ZnMgO film by using negative photoresist photoetching, and removing the interdigital electrode mask after sputtering metal on the interdigital electrode mask to form an interdigital electrode; and S3, pressing In particles on the interdigital electrode to obtain the ZnMgO ultraviolet detector with the MSM structure. Compared with the priorart, the oxygen flow is increased, the oxygen partial pressure is increased, and oxygen defects are reduced; the prepared ZnMgO film has the characteristics of high crystallization quality, no phasesplitting, steep absorption cut-off edge and the like, and the ZnMgO film 2 with the mixed-phase structure can simultaneously meet high responsivity and low dark current, so that the ZnMgO ultravioletphotoelectric detector has lower dark current and higher photoresponse speed.