Mumbai, India

dqureshiumar@gmail.com

How to connect Django with MySQL

Home  /  How to connect Django with MySQL

Connecting our Django Project to MySQL

by Umar Qureshi


To connect MySQL as a database in our Django Project we need to install MYSQLCLIENT


  • Download the file from the above provided link or go to Click Here


  • Open the path in your command prompt where you have downloaded the file


  • Run pip install mysqlclient-1.4.6-cp38-cp38-win32.whl
    Note : if you are using virtual environment so install it under your virtual environment
    Check how to setup virtual environment in python


  • If you are using XAMPP Server start the Apache Server and MySQL

    Xampp Server

    Note down the port number on which Mysql Server is running. In my case it's 3306



  • Go to your Django Project's settings.py file

    Django Project Skeleton


  • Create a Database in your MySQL

    Creating a new Database


  • In the Databases change your database configuration to this :

    Database Configuration


  • Run "python manage.py makemigrations"



  • Run "python manage.py migrate"
    You can see your tables getting migrated to your database

    Tables after running migrate command


  • Thus by following these steps we can Connect our Django Project to MySQL using MYSQLCLIENT. If any queries you can get back to dqureshiumar@gmail.com.
    Hope you liked it.
    Thank You.