The present invention provides an electroplating method of magnesium and magnesium alloy. The technology comprises dehydrogen, chemical degreasing, shining, neutralization, activation, pre-plating, functional plating, decorative plating and post treatment. The cast workpiece must be water-washed between every two procedures. The current density of pre-plating is 5-15 A / dm2, cell voltage 4-12 V, pH value of pre-plating solution 1.0-1.2, and Baume degree at room temperature is 30-35. Pre-plating solution recipe contains: copper fluoborate, fluoboric acid, alanine, polyethylene glycol and alizarin dye, mixture of itaconic acid and MBT, 3-S isothiourea onium salt propane sulfonate ,R-S-S(CH2)SO3Na and deionization water. The pre-plating solution of the present invention is cyanogen free, non-toxic and non-hazardous. Bond strength between pre-plating layer and substrate material and between pre-plating layer and the post functional plating layer or decorative plating layer is good. The plating layer is bright and has good corrosion resistance, wear resistance and decorative effect.