Connecting switches between two buildings, each building has it own mains electrical supply

It won't be a problem. The Ethernet standards for twisted-pair have always required isolation of the signal wires from all local power supplies and grounds. In most equipment using twisted-pair Ethernet this is achieved simply by having all of the pairs run through transformers at each end. There is therefore no metallic connection between the switches or whatever the TP cable is plugged into, and therefore complete isolation, between the equipments' grounds and power supplies.

If you were using shielded twisted pair, you would want to connect its shield to building frame ground at one and only one end. This was a concern back in the days of 10Base2 and 10Base5 (Ethernet over coax).


If you're at all concerned about it, you can fairly cheaply use a fiber-optic connection instead. That completely avoids the issue by being non-conductive.

Gigabit media converters run for $50–100 a piece, allowing you to fairly cheaply user fiber instead. (Search Amazon or wherever for something like "fiber media converter" and you'll find plenty). This does require running fiber — and that's only easy if you can pull a pre-terminated fiber through existing conduit; that'll add around another $20 for the fiber. If anything is going to fail, it's going to be a media converter (or its power supply); therefor, keep a spare on hand. Total of under $200 including spares easily doable.

Note that there are multiple fiber connectors, so you need to make sure the pre-terminated fiber you buy matches the media converters. At the distance you're running (meters, not kilometers), everything will be multimode fiber and fairly low-power.

[Of course, if you have the tools and know-how to terminate fiber, that makes it easier, you can pull unterminated fiber through a much smaller or more tightly packed conduit. But then I suspect you'd have already considered this option.]