Grossly, it does not matter what buffer you use. It is the pH that matters.
For DNA electrophoresis EDTA is added in order to chelate divalent cations that serve as cofactors for nucleases. Tris is the base of the buffer and is used to set pH. Along with Tris one can use Boric acid, Acetic acid or phosphoric acid for adjusting the pH.
The buffering range can be obtained by the Henderson-Hasselbalch equation.
The choice of buffers depends on pH range, ease of preparation/storage and fine resolving properties and runtime properties such as heating etc (also mentioned by others).
MOPS is another buffering agent. I am not very sure why MOPS is used instead of Tris for RNA gels; perhaps the latter forms adducts with formaldehyde by Mannich's reaction whereas MOPS cannot undergo that reaction. MOPS is also a Zwitter-ionic species and maintains neutral pH. RNA should not be kept in alkaline pH. At acidic pH, RNA will become neutral and will not move.
For protein electrophoresis things are a little different. Glycine-Chloride buffer is used because it allows stacking.