michael@slashetc:~$

Linux socket-to-socket tunnel (MySQL example)

$ socat "UNIX-LISTEN:/tmp/mysqld.temp.sock,reuseaddr,fork" EXEC:"ssh username@remoteserver.com socat STDIO UNIX-CONNECT:/var/run/mysqld/mysqld.sock"</p>

Won't work with password login. You must add your RSA key to the server's authorizedkeys file, or change the ssh command adding the -i option for a custom RSA key:

socat "UNIX-LISTEN:/tmp/mysqld.temp.sock,reuseaddr,fork" EXEC:"ssh username@remoteserver.com -i /home/user/rsa-keys/id_rsa socat STDIO UNIX-CONNECT:/var/run/mysqld/mysqld.sock"

---

/tmp/mysqld.temp.sock will be created locally by socat, don't create it yourself. The folder it lives must be writable. Connect your MySQL client to this socket, with database and username set properly.

---

In case you need to forward a remote socket to a LOCAL PORT instead, check http://www.commandlinefu.com/commands/view/9436/socat-tcp-listen5500-execssh-userremotehost-socat-stdio-unix-connectvarrunmysqldmysqld.sock

commandlinefu.com

Diff your entire server config at ScriptRock.com

</div>

Read More here.