1

I've installed NGINX, GUNICORN and my project properly on Ubuntu server, but when I run the project using python manage.py runserver, I get the following error;

django.db.utils.OperationalError: (2003, "Can't connect to MySQL server on '127.0.0.1' (111)"

Before, installing gunicorn, my site was running properly at my_public_ip_address:8000

worldofjr
  • 3,868
  • 8
  • 37
  • 49

3 Answers3

2

check your mysql server is running or not restart the mysql server

1

as asked before if you are running your website on a remote server, you should make sure that you add the ip address to the ALLOWED_HOSTS-list otherwise you might get another error.

Solutions could be:

  • Did you try to uninstall gunicorn? gunicorn is used later for the deployment of the website so it should actually be fine, as you are starting a development server with python manage.py runserver
  • As nginx is also used to ship your website into production if would assume that this should note be related directly to the database. you might want to check if nginx is running with service nginx status if this allocates the localhost port django can maybe not access the mysql database
  • Did you check the port config of your mysql database?
Moritz
  • 105
  • 2
  • 6
1

I had the same problem and just noticed that in my Linux home .bashrc file I had changed before

EXPORT DATABASE_HOST = 127.0.0.1
EXPORT DATABASE_PORT = 5432 # change here as 3306 

When I changed these environment variables it worked.

adnan kaya
  • 531
  • 3
  • 13