Successive ionisations

The energy required to remove an electron from a gas phase atom is the first ionisation energy. Additional electrons can be removed if energy is supplied because these reactions are endothermic.

Mg(g) Mg+(g) + e first ionisation

Mg+(g) Mg2+(g) + e second ionisation

Mg2+(g) Mg3+(g) + e third ionisation
 
successive IE Mg

The graph shows that

removal of each successive electron requires more energy
This is because the electron is being removed from a species that is already positive.

the ionisation energy is much higher for removal of electrons beyond the valence shell.
This is because the electrons in the shell below the valence shell are much closer to the nucleus therefore even more difficult to remove from a species that is already positive.

 in the case of magnesium (3s2), the third ionisation enthalpy is significantly higher than the second.

Magnesium exists in its compounds as Mg2+ (not Mg+) because the energy required to remove the second electron is more than compensated by other gains in energy during compound formation.