0% found this document useful (0 votes)
8 views3 pages

Django MySQL Connection Guide

This document provides a step-by-step guide to connect a Django project to a MySQL database, including installation of the MySQL client, configuration of the settings.py file, and running migrations. It also includes example model code for a Student and Course, as well as a list of default Django tables created for user authentication and session management. Following these steps will enable the Django application to utilize MySQL as its database.
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
8 views3 pages

Django MySQL Connection Guide

This document provides a step-by-step guide to connect a Django project to a MySQL database, including installation of the MySQL client, configuration of the settings.py file, and running migrations. It also includes example model code for a Student and Course, as well as a list of default Django tables created for user authentication and session management. Following these steps will enable the Django application to utilize MySQL as its database.
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd

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.

You might also like