[PYTHON] Use MySQL with Django

Introduction

Here, we will explain the settings for using MySQL as the django database instead of the standard sqlite. In addition, it is assumed that MySQL is installed by MAMP.

Declaration of database to use

First, in manage.py, specify that you will use MySQL as follows.

manage.py


import pymysql


pymysql.install_as_MySQLdb()

Description of database information to use

Then write the detailed information of the database in settings.py.

settings.py


DATABASES = {
    'default': {
        'ENGINE': 'django.db.backends.mysql',
        'NAME':Database name,
        'USER':Username (of your database),
        'PASSWORD':Password (of your database),
        'HOST': '/Applications/MAMP/tmp/mysql/mysql.sock',
        'PORT': '8889'  #For MAMP,
    }
}

Recommended Posts

Use MySQL with Django
Use Unicode 6.0 emoji with django / MySQL
Use Gentelella with django
Use LESS with Django
Use prefetch_related conveniently with Django
Internationalization with django
CRUD with Django
Django + MySQL settings
Authenticate Google with Django
Django 1.11 started with Python3.6
Upload files with Django
Development digest with Django
Use RTX 3090 with PyTorch
Use ansible with cygwin
Use pipdeptree with virtualenv
Output PDF with Django
[Python] Use JSON with Python
Use Mock with pytest
Markdown output with Django
Twitter OAuth with Django
Use MySQL from Python
Use tensorboard with Chainer
Use DynamoDB with Python
Use pip with MSYS2
Getting Started with Django 1
Use Python 3.8 with Anaconda
Use pyright with Spacemacs
File upload with django
Use python with docker
Use MySQL from Python
Azure External Storage MySQL Challenges with Django (PTVS)
Pooling mechanize with Django
Use Enums with SQLAlchemy
Use Python / Django with Windows Azure Cloud Service!
Use tensorboard with NNabla
Use GPS with Edison
Start today with Django
Getting Started with Django 2
Use nim with Jupyter
Do Django with CodeStar (Python3.6.8, Django2.2.9)
Use Trello API with python
Use shared memory with shared libraries
Use "$ in" operator with mongo-go-driver
Use directional graphs with networkx
Get started with Django! ~ Tutorial ⑤ ~
Use TensorFlow with Intellij IDEA
Minimal website environment with django
Create an API with Django
Use Twitter API with Python
Use pip with Jupyter Notebook
Do Django with CodeStar (Python3.8, Django2.1.15)
Deploy Django serverless with Lambda
Python3 + Django ~ Mac ~ with Apache
Use DATE_FORMAT with SQLAlchemy filter
Use TUN / TAP with Python
Getting Started with Python Django (1)
Django Getting Started: 4_MySQL Integration
Use sqlite3 with NAO (Pepper)
Use MySQL from Anaconda (python)
Create a homepage with django
Use sqlite load_extensions with Pyramid