The refining of a metal (as copper) by electrolysis is electrorefining. The crude metal is used as the anode going into solution and the pure metal being deposited upon the cathode.
In case of copper, the electrolyte is an acidic solution of copper sulphate. By passing electricity through the cell, copper is dissolved from the anode and deposited on the cathode. However impurities either remain in solution or collect as an insoluble sludge.
We hope that clarifies your query.