magnesium sulfate is an ionic compound.
Mg 2+ is the cation and SO4 2- is the anion and the electrostatic attraction between the two helps maintain the ionic bond that holds the compound together.