简体   繁体   中英

How to connect django with mysql database proberly

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

端口 3306 是 MySQL 协议的默认端口,由 mysql 客户端使用您正在使用 5432,这是 Postgresql 的默认端口。

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM