django + mysql setting (Mac or Linux)

A. mysql install

1. download mysql


* site may ask to join, but we don't need to join for download file
* install -> in case of Mac, show default password on popup window.

2. set path

$nano ~/.bash_profile 
add this sentence 

export PATH=/usr/local/mysql/bin:$PATH

3. start mysql & set password

$ sudo /usr/local/mysql/support-files/mysql.server start

create a username with a password
$ mysqladmin -u root password yourpassword
change the password
$ mysqladmin -u root -p'oldpassword' password newpassword

4. create mysql database

$ mysql -u root -p
Enter password:

create database
CREATE DATABASE taskbuster_db;

B. django setting

1. install pymysql

$pip install pymysql

2. django settings.py

import pymysql

    'default': {
        'ENGINE': 'django.db.backends.mysql',        
'NAME': 'django_locker', # DB name        
'USER': '', # database user : root        
'PASSWORD': '', # database pass         
'HOST': '', # localhost        
'PORT': '', # database port('' or 3306)    }

3. migration

$python manage.py makemigrations

$python manage.py migrate

No comments:

Post a Comment