Connect to Proxy (SOCKS) Database in python Connect to Proxy (SOCKS) Database in python database database

Connect to Proxy (SOCKS) Database in python


I think an option is to mount a local tunnelling sock with port forwarding, to map your database port and act as if your server where a localhost one.

It's really efficient if you're running your python script on a Unix computer.

Something like this system call (for a 3306 mariaDB) :

ssh -L 3306:localhost:3306 user@x.x.x.x

First, your run SSH, then, you tell him to enable a port forwarding from the 3306 port to the localhost:3306 port of the server you connect through user@IP.

With this, every query from your local machine:3306 will by send to your MariaDB:3306 server, allowing you to use it as if you where on the server.


If you do not want to hack into pymssql source code, there're external tools that redirect all TCP traffic over the socks proxy, such as FreeCap for Windows, RedSocks for Linux and Proximac for macOS.