1

First of all im tring to connect a django_project to mysql by editting my_project/settings.py file with the code below

I created a database called (mydatabase) and user with full privileges called (admin) identified by (admin), then i tried to connect my django project with mydatabase by the following code below:

django_project\mysettings.py

DATABASES = { 'default': { 'ENGINE': 'django.db.backends.mysql', 'NAME': 'mydatabase', 'USER': 'admin', 'PASSWORD': 'admin', 'HOST': '127.0.0.1', 'PORT': '5432', } 

}

Everything was working as expected until i changed that DATABASES dictionary from the default value in file above and it resulted by the following error when i tried to run the server with py manage.py runserver

Watching for file changes with StatReloader

performing system checks...

MySQLdb._exceptions.OperationalError: (2013, "Lost connection to MySQL server at 'handshake: reading inital communication packet', system error: 0") django.db.utils.OperationalError: (2013, "Lost connection to MySQL server at 'handshake: reading inital communication packet', system error: 0") 

I didn't provide the traceback for the error as it seemed unneccessary, I would provide it if needed


I have both mysql client and mysql connector modules installed :

mysql-connector-python 8.0.19 mysqlclient 1.4.6 
3
  • Are you sure your this is mysql and is on port 5432? Commented Feb 22, 2020 at 13:42
  • set HOST to localhost and port 3306 if your database is on local Commented Feb 22, 2020 at 13:48
  • @iklinac Oh, it isn't, actually it's 3306 and it worked when i changed it ty, I thought while using django for devolpment purposes i must use the 5432 port but it works fine now after changing it to 3306 Commented Feb 22, 2020 at 13:51

1 Answer 1

2

Port 3306 is the default port for the MySQL Protocol, which is used by the mysql client You are using 5432 which is default for Postgresql.

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

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.