How to connect django with MySql database?
author
,
Aspirant Programmer

Please describe in detail to connect Django application with MySql database?

  • Total 1 Answer
  • 351
Can You answer this question?
author
,
Aspirant Programmer

Django comes with sqlite as database backend but you can use any of the database as per your need. To use MySql as database in django you will need to do some modification in settings.py file in DATABASES dictionary, refer to below line of code to proceed easily:

By default you will see below code:

DATABASES = {
    'default': {
        'ENGINE': 'django.db.backends.sqlite3',
        'NAME': os.path.join(BASE_DIR, 'db.sqlite3'),
    }
}

 

To use MySql database, mention below information:

DATABASES = {
    'default': {
        'ENGINE': 'django.db.backends.mysql',
        'NAME': 'ABC',  ##Database Name
        'USER': 'root',
        'PASSWORD': '',
        'HOST': '127.0.0.1',
        'PORT': '3306',
    }
}

Update above information as per your environment.