Relativistic mean-field study of Mg isotopes