Magnesium chloride, like other ionic compounds, is a strong electrolyte which means it completely dissociates into its ions in aqeuous solution (i.e. when dissolved in water). In order for something to conduct electricity, there have to be charge carriers to move the charge from one location to another. This can happen in solutions that have ions present or in metals where the electrons are not "tied" to a single atom but are usually described as being in a "sea of electrons" shared by all atoms. While solid magnesium chloride does not have the ability to conduct electricity; molten ionic salts will conduct electricity.
Substances such as glucose or sucrose are non-electrolytes and do not break up in water. Therefore they are not conductors of electricity.
If we need ions in water, then why do we have to worry about water and electricity? Pure water breaks up a very small amount in water which wouldn't carry much charge but the reality is that most water is not very pure and there is a sufficient concentration of particles available in the water to carry a charge.