The use of magnetic field to actively control Electrical Discharge Machining(EDM) can effectively improve the problems of low material removal rate and poor surface quality, but due to the limitation of materials, the magnetic induction intensity of permanent magnets after magnetization is not high, and the magnetic induction lines of permanent magnets are too concentrated and difficult to control. In order to overcome the above shortcomings, this study applied the Halbach array magnetic field to the field of EDM for the first time, established a model of the trajectory of the charged particle beam in the discharge channel, analyzed the influence of the Halbach array magnetic field on the discharge channel, and clarified the improvement mechanism of the Halbacch array magnetic field in EDM. In addition, several sets of experiments were carried out by controlling the distance between the workpiece and the working surface of the Halbach array permanent magnets. The experimental results show that when the distance between the workpiece and the working surface of the Halbach array permanent magnet is less than 10mm, the material erosion rate of the workpiece increases significantly, and the electrode loss rate and surface roughness decrease significantly. When the workpiece is 0mm away from the working surface, the material removal rate is increased by 18.18%, from 0.4513mm3/min to 0.5333mm3/min, the tool wear ratio is reduced by 46.87%, from 0.2587 to 0.13745 mm3/min, and the surface roughness is reduced by 39.56%, from 4.186 μm to 2.53 μm.