Just use SSH tunneling. To make your work easier, you can install autossh , which automatically checks if the ssh connection is alive and restores it if it drops.
Then you can open the tunnel using the following command:
autossh -f -N -L LocalPort:MySQLAddress:MySQLPort your_login@your _server
Where:
your_server - the server you are connecting to through sshyour_login - your username in your_serverLocalPort - any unused port on the computer running Django. This port will be used for the tunnel.MySQLAddress is the address of your MySQL server, since it is accessible from your_server (that is, if MySQL is running on your_server , it will be 127.0.0.1 )MySQLPort - MySQL port is listening
Then in Django settings you specify MySQL IP as 127.0.0.1 and port as LocalPort , which you installed above.
Example:
autossh -f -N -L 10000:127.0.0.1:3306 a_user@192.168.1.3
When you run this command, you will listen for the SSH tunnel on local port 10000. Therefore, if you connect to localhost: 10000, your connection will be tunneled to localhost: 3306 on server 192.168.1.3.
source share