Ali Hayder
Ali Hayder

Reputation: 361

Django install/deploy with mysql

I have xampp on my system. I installed Django also. From last two days I am trying to integrate MySQL with Django. I also tried for Django with xampp but each individual tutorial/process from various links and youtube have failed. Now I can't even run my apache server from xampp.

I also tried Bitnami Django Stack but it clashes with my existing xampp's apache and MySQL ports.

My question is how can I use MySQL(I use xampp for development so I want to use MySQL which is installed with xampp) as a database for Django projects?

Upvotes: 2

Views: 754

Answers (3)

root
root

Reputation: 582

  1. Create any database(DB_NAME) which you want to use on your Django Project.
  2. Edit your settings.py file

    DATABASES = { 'default': { 'ENGINE': 'django.db.backends.mysql', 'NAME': 'DB_NAME', 'HOST': '127.0.0.1', 'PORT': '3306', 'USER': 'root', 'PASSWD': '', }}

  3. Install the following packages in the virtualenv (if you're using django on virtualenv, which is more preferred):

    sudo apt-get install libmysqlclient-dev

    pip install MySQL-python

  4. That's it!! you have configured Django with MySQL in a very easy way.

  5. Now run your Django project:

    python manage.py migrate

    python manage.py runserver

Upvotes: 2

Prasanth K C
Prasanth K C

Reputation: 7332

You have to install mysql-python module to make it working

Follow this tutorial to setup mysql in your django environment.

SETUP MYSQL WITH DJANGO >>

Upvotes: 0

alecxe
alecxe

Reputation: 474171

You need to set DATABASES dictionary in settings.py and point to your mysql server:

A dictionary containing the settings for all databases to be used with Django. It is a nested dictionary whose contents maps database aliases to a dictionary containing the options for an individual database.

Example:

DATABASES = {
    'default': {
        'ENGINE': 'django.db.backends.mysql',
        'NAME': 'mydatabase',      
        'USER': 'myuser',
        'PASSWORD': 'myuserpassword',
        'HOST': '127.0.0.1', 
        'PORT': '3306'
    }
}

Upvotes: 2

Related Questions