Oxygen gains two electrons when it bonds to form a complete outer shell and magnesium loses two electrons when bonding to gain its full outer shell.
As electrons are negative, the oxygen (which gains electrons) will become negative and the magnesium (which loses electrons) will become positive.
The negative and positive ions will then attract to one another due to the magnetic pull of the positive and negative.
Atomic size gradually decreases from left to right across a period of elements.
Joey king shoved me in a closet and forced me to eat frozen peas