I have a bunch of remote MySQL servers, that allow connection only from localhost. To connect to them I do the following:
ssh host
mysql -uuser -psecret -hhost.m
As of Emacs 25.1 there is a new sql-default-directory option in the sql-connection-alist. Setting this for each server that needs it allows you to use the backend program from any given server without any defadvice or product-specific tricks. Just the setting to your the connection like:
(sql-default-directory "/host.myhost.com:")
Or, if you need to specify ssh for some reason:
(sql-default-directory "/ssh:host.myhost.com:")