STEP-BY-STEP GUIDE: Connect Django to MySQL
1. Install MySQL Client
Run this in your terminal:
pip install mysqlclient
2. Configure [Link] in Django project:
Replace the DATABASES section with:
DATABASES = {
'default': {
'ENGINE': '[Link]',
'NAME': 'your_database_name',
'USER': 'your_mysql_username',
'PASSWORD': 'your_mysql_password',
'HOST': 'localhost',
'PORT': '3306',
3. Create MySQL Database:
Use MySQL Workbench or terminal to create the database before running migrations.
4. Run Migrations:
python [Link] makemigrations
python [Link] migrate
5. Run the server and it will use MySQL as the database.
-------------------------
[Link] Example Code:
from [Link] import models
class Student([Link]):
name = [Link](max_length=100)
email = [Link](unique=True)
age = [Link]()
joined_date = [Link](auto_now_add=True)
class Course([Link]):
title = [Link](max_length=100)
description = [Link]()
credits = [Link]()
-------------------------
Default Django Tables Created:
1. auth_user - Stores users info
2. auth_group - User groups
3. auth_permission - Permissions
4. django_admin_log - Admin actions logs
5. django_content_type - Links models with permissions
6. django_migrations - Tracks applied migrations
7. django_session - Stores session data
8. django_site - Site framework (optional)
9. django_auth_group_permissions - Links groups and permissions
10. django_auth_user_groups - Links users and groups
11. django_auth_user_user_permissions - Links users and permissions
These tables are essential for authentication, session management, and admin functionalities.