Python/Django

[Django, MySQL] Django MySQL 셋팅하기

yubi5050 2022. 7. 13. 22:43

👉 1. MySql 설치

https://www.mysql.com/downloads/

 

MySQL :: MySQL Downloads

MySQL Cluster CGE MySQL Cluster is a real-time open source transactional database designed for fast, always-on access to data under high throughput conditions. MySQL Cluster MySQL Cluster Manager Plus, everything in MySQL Enterprise Edition Learn More » C

www.mysql.com

 

👉 2. Django-mysql Connector 설치

$pip install mysqlclient

 

👉 3. mysql workbench 접속해서 Create Database

mysql workbench 설치 완료시, root 계정으로 접속해서 schema (=database) 를 생성

 

 

👉 4. Django settings.py / my_settings.py 작성 

일반적으로 key 보호를 위해 my_settings.py 에 따로 작성하여 import 함

# settings.py
import my_settings
DATABASES = my_settings.MYSQL_DATABASE

# my_settings.py
MYSQL_DATABASE = {
    'default': {
        'ENGINE': 'django.db.backends.mysql',
        'NAME': '<your schema name>', # Schema Name
        'USER': 'root', # USER NAME
        'PASSWORD': <your passwd>, # PASSWORD NAME
        'HOST':'127.0.0.1',
        'PORT':'3306',
    }
}

 

👉 5. Django ORM을 Mysql 에 migrate

$ python manage.py makemigrations
$ python manage.py migrate