Skip to content
Related Articles
Open in App
Not now

Related Articles

How to integrate Mysql database with Django?

Improve Article
Save Article
Like Article
  • Last Updated : 03 Oct, 2022
Improve Article
Save Article
Like Article

Django is a Python-based web framework that allows you to quickly create efficient web applications. It is also called batteries included framework because Django provides built-in features for everything including Django Admin Interface, default database – SQLlite3, etc. 


Install the Mysql database, After downloading install the setup and set the admin and password.

Install Django

pip install django

Then install another library to use the MySQL database

pip install mysqlclient

Steps to connect MySQL to Django

Step 1: Create a new project

django-admin startproject MyDB

Step 2: Move to the MyDB folder.

cd MyDB

Step 3: Create a MySql database.

Step 4: Update the

Open here inside the DATABASES variable configure MySQL database values, and add values of your database.


    'default': {
        'ENGINE': 'django.db.backends.mysql',
        'NAME': 'mydb',
        'USER': 'root',
        'PASSWORD': 'admin',

First, we have replaced the ‘django.db.backends.sqlite3’ to ‘django.db.backends.mysql’. This is basically indicating we shift SQLite to MySQL database.

  • NAME: It indicates the name of the database we want to connect.
  • USER: The MYSQL username is the one who has access to the database and manages it.
  • PASSWORD: It is the password of the database. 
  • HOST: It is indicated by “” and “PORT” “3306” that the MySQL database is accessible at hostname “0.0.1” and on port “3306.”

Step 5: Run the server.

python runserver

Step 6: Run the migration command

python makemigrations
How to connect MySQL to Django


python migrate
How to connect MySQL to Django


My Personal Notes arrow_drop_up
Like Article
Save Article
Related Articles

Start Your Coding Journey Now!