Using MySQL Database with Django Project

Mahabubur Rahman
Initially Django support Sqlit and Postgresql Database, but by installing the MySQL client package we can use MySQL database with the Django project.

So now I will describe the necessary configuration required to connect Django with the MySQL database.

Step - 1: Installing MySQL Client
Install MySQL client through pip using the command 

pip install mysqlclient

Step - 2: Setting Database Connection 
Open the file of the Django project. Here update the database connection settings as bellow

DATABASES = { 'default': { 'ENGINE': 'django.db.backends.mysql', 'NAME': 'test_dashboard', 'USER': 'test_user', 'PASSWORD': 'test_pass', 'HOST': 'localhost', 'PORT': '3306', } }
Here -
ENGINE : database engine.
NAME : database user name.
PASSWORD : database user password.
HOST : database server host.
PORT : database port.

Step - 3: Make Migrations
Now run the below commands - 

python makemigrations
python migrate

This will migrate all Django Models to MySQL schema.

This is how you can connect your Django web application with the MySQL database.

If this article was helpful leave a comment.

Post a Comment

  1. Thank you for sharing lot of information. Very informative post. Covered almost everything. Please Keep sharing such a useful content for us. please continue this work, also refer some informative blogs on Product Engineering Services for more contents about the product service based knowledge

  2. Thank you for sharing this valuable information.

    Apparrant is the leading UX UI Design agency having experienced designers and developers working throughout the year on important and life changing products. We have been awarded as top UI UX Design agency in India by multiple agencies. If you are looking for best UX Design Agency in Noida, UI UX Design Agency in Faridabad, and UX UI Design Company in Delhi then Apparrant is best for you.

Post a Comment