Is a ionic bond
Magnesium has two valence electrons and an electronegativity of 1.2, while oxygen has six valence electrons and an electronegativity of 3.5. Since oxygen has a higher electronegativity, it attracts the two valence electrons from the magnesium atom and these electrons are transferred from the magnesium atom to the oxygen atom. Magnesium loses two electrons to form Mg2+, and oxygen gains two electrons to form O2−.
The attractive force between the oppositely charged ions is what holds the molecule together.