Remote database using ssh

204 views
Skip to first unread message

Wennie Catabay

unread,
Jul 19, 2022, 11:32:55 AM7/19/22
to Django users
Hello,

I am stuck on defining how to connect a remote database from another server using ssh. I am able to connect the remote database with putty using ssh, but but I don't know how to apply it in django.

Thank you.

Anh Nguyen

unread,
Jul 19, 2022, 11:50:52 AM7/19/22
to django...@googlegroups.com
Public db port but not recommend for security reason and performance.

--
You received this message because you are subscribed to the Google Groups "Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to django-users...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/d0c2f56f-c739-4508-8529-4c5107f08636n%40googlegroups.com.

Mr.Teapot

unread,
Jul 19, 2022, 2:57:53 PM7/19/22
to Django users
Probably your database is not listening for remote connections for security reasons. Do the database and your application server are in the same network? Or maybe you are able to set up a VPN for both of these machines. Last but not recommended solution you can open a public port and allow only specyfic IP to connect and change the database settings to listen not only for local connections.

Sebastian Jung

unread,
Jul 19, 2022, 5:11:37 PM7/19/22
to django...@googlegroups.com
Hey,

This is easy and have nothing to do with django. Yoz must make port forwarding over ssh from postgres port.


Regards

--

Wennie Catabay

unread,
Jul 19, 2022, 9:06:10 PM7/19/22
to Django users
Thank you for the response. I followed some guide to connecting remote database with my application, I found solution to access remote database with SSHTunnelForwarder and mysql.connector.connect() and it says in my log "Connected to my remote database" (Screen shot attached), 

The problem is when I access remote database in DATABASES with multiple database and run the command "python manage.py migrate --database=remote_db" the response is error(screen shot attached). but When I run Command  'python manage.py inspectdb --database=remote_db' it successfully created model structure from remote database.

Screenshot 2022-07-20 090207.png
Screenshot 2022-07-20 083318.png

Abdul Qoyyuum

unread,
Jul 19, 2022, 11:15:05 PM7/19/22
to django...@googlegroups.com
We don't know if your DB is in the same network or not as your Django App server but the answer is to open the database port on the database server. If you're using postgresql on the Database, then install a psql client on the app server and test connect from there. If it works, then your Django should also work too.

--
You received this message because you are subscribed to the Google Groups "Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to django-users...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/d0c2f56f-c739-4508-8529-4c5107f08636n%40googlegroups.com.


--
Abdul Qoyyuum Bin Haji Abdul Kadir

Wennie Catabay

unread,
Jul 20, 2022, 3:09:09 AM7/20/22
to Django users
No, it is not the same network,  the remote database is MySql, and my default database in my Django application is Postgres, I only want is to  read or get data to the remote database into may Django application. 

Wennie Catabay

unread,
Jul 20, 2022, 3:51:45 AM7/20/22
to Django users
Thank a lot for your response, I found the solution after I got this error, " CommandError: You appear not to have the 'mysql' program installed or on your path. "
and I use xamp in the path variable. and it solved the issue. thank.

Reply all
Reply to author
Forward
0 new messages