Magnesium will give its two valence electrons to oxygen and it will have a charge of 2+(positive). It will also complete its octet, getting balanced.
Oxygen will take two electrons from magnesium getting a charge of 2-(negative). It will also complete its octet.
When making the formula, the two charges will cancel out each other giving the formula MgO.
It is an ionic bond.