As far as I know, this cannot be done through the command line, because the mysql command does not support proxy connections.
If the client and server are on a UNIX machine, and one of them is accessible externally, I suggest using the SSH tunnel. This is basically a secure, tunneled TCP connection that can be used for anything, and the local mysql command can easily connect to the tunnel port.
If this parameter is missing, you can write some kind of executable wrapper file. For example, Java and Ruby have libraries that allow you to talk to SOCKS proxies and connect these sockets before implementing the MySQL or JDBC protocol. What happens then depends entirely on what you have planned next.
source share