Forums

Connect Django app on pythonanywhere.com to remote MySQL server

I have a MySQL database on another web hosting service. I would like to connect my django app on pythonanywhere.com to that MySQL database. I was able to create a ssh connection from pythonanwhere to my remote database, but I can't seem to have django recognize that database. After opening the ssh connection - I opened a new bash console and tried running python manage.py inspectdb. It produced the following errror.

django.db.utils.OperationalError: (2002, "Can't connect to local MySQL server through socket '/var/run/mysqld/mysqld.sock' (2)")

Is this even possible. Am I doing something wrong?

It may be possible, but you need to be aware that different consoles may be running on different servers, so your SSH connection may exist in one of your consoles, but not in another. Also I think it's going to be really difficult for you to connect to that database from your web app. That will be on another server and getting the SSH session started in a web app will be difficult, if not impossible.