Django Archives - wiki

Django connecting with mysql database

step 1

we need to install mysql module

pip install PyMySQL

step 2

configure mysql in settings.py

eg:-1

# Database
# https://docs.djangoproject.com/en/1.6/ref/settings/#databases

DATABASES = {
    'default': {
        'ENGINE': 'django.db.backends.mysql',
        'NAME': 'pypaywheel',
        'USER': 'root',
        'PASSWORD': 'password',
        'HOST': '192.168.1.174',
        'PORT': '',
        'OPTIONS': {'charset': 'utf8mb4'},
    }
}

eg:-2

DATABASES = {
    'default': {
        'ENGINE': 'django.db.backends.mysql',
        'NAME': 'djangoblog',
        'USER': 'root',
        'PASSWORD': 'password',
        'HOST': 'localhost',
        'PORT': '',
        'OPTIONS': {'charset': 'utf8mb4'},
    }
}
By bm on July 8, 2014 | Python Django | A comment?
Tags: