Django REST framework × MySQL Commonly Used Commands (Memo)

2025-06-04

Install dependencies

pip install -r requirements.txt

Database migration

python manage.py makemigrations app_name
# app_name is the name of the app

Apply migrations

python manage.py migrate

Create superuser

python manage.py createsuperuser

Show migration list

python manage.py showmigrations

Python

Virtual environment activation

  • Mac

    source path_to_virtual_env/bin/activate
  • Windows

    venv\Scripts\activate.bat

Deactivate virtual environment

deactivate

MySQL

Connect

mysql -u user -p
# Replace user with the username

Start server

mysql.server start

Restart server

mysql.server restart

Show databases

mysql> SHOW DATABASES;

Select a database

mysql> USE selectDB;
# selectDB is the name of the database you want to use

Show tables

SHOW TABLES;

Set user password

CREATE USER 'user'@'localhost' IDENTIFIED BY 'password';
# Run as root. Replace user, localhost, and password accordingly

Grant ALTER privilege

GRANT ALTER ON *.* TO 'user'@'localhost';
FLUSH PRIVILEGES;

Check user privileges

SHOW GRANTS FOR 'user'@'localhost';

Grant all privileges on a specific database

GRANT ALL PRIVILEGES ON database.* TO 'user'@'localhost';
# Replace user, localhost, and database as appropriate

Common privileges:

  1. SELECT: Select data from a table
  2. INSERT: Insert