a solid ionic compound can't be electrolysed because the ions are fixed in place and can't move.
moltenionic compounds can be electrolysed, because the ions are free to move.
positive metal ions/cations are reduced [gain electrons] to atoms at the cathode. negative ions are oxidised to atoms as the anode.
in aqueous solutions, there will be the ions from the ionic compound and hydrogen ions + hydroxide ions.
at the cathode, if H+ions and metal ions are present, hydrogen gas will be produced if the metal is more reactive than hydrogen. [sodium, potassium, lithium, iron, chromium, nickel, tin, lead]
at the anode, if halide ions are present, molecules of halides will be formed. if no halide ions are present, then oxygen will be formed from the hydroxide ions.