First identify which is being oxidized and reduced. In this case, the Mg is being oxidized and the Hg is being reduced.
Mg --> Mg+2
Hg+2 --> Hg+1
Then you have to balance each half reaction first with electrons before adding them together in one equation
[tex]Mg [/tex] ⇒ [tex] Mg^{+2} + 2e^{-1} [/tex]
and
[tex]2Hg^{+2} + 2e^{-1} [/tex] ⇒ [tex]Hg_{2} ^{+2} [/tex]
and then combine them together to form
[tex]Mg + 2 Hg^{+2} + 2e [/tex] ⇒ [tex] Mg^{+2} + 2e ^{-} + 2 Hg^{+1} + 2 e^{-} [/tex]
It isn't necessary to keep the electrons but its essential to know how many there are in order to know how many are in the equation in order to calculate the reaction energy. Note: Add H+ and H2O to balance the H's and O's in acidic solution if needed.