Set Up Local Environment for MySQL (Python + Django + XAMPP)

Set up local database – XAMPP
XAMPP has the full package for Apache + MySQL. “phpMyAdmin” is used for database management, which will be useful when import local database to web db (ex. pythonanywhere.com)

Install python package to interact with MySQL database
Option 1: import MySQLdb
pip install mysql-python (python 2.7) / pip install mysqlclient (python3.x)
Option 2: import mysql.connector
pip install mysql-connector-python

Configure Django to access a local MySQL database
Edit project setting.py file:

DATABASES = {
'default': {
'ENGINE': 'django.db.backends.mysql',
'NAME': 'database_name',
'USER': 'root',
'PASSWORD': 'root_password',
'HOST': 'localhost',
}
}

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s