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

1
  • Are you running your site on a remote server ? Commented Jan 22, 2019 at 16:08

3 Answers 3

3

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

Sign up to request clarification or add additional context in comments.

Comments

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?

Comments

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.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.