Sunday, 25 August 2013

Django Settings for MySQL

Building a Django site with a MySQL database back end is straightforward.  You'll need MySQL-Python ("pip install mysql-python" if you have python pip installed). 

Then configure the DATABASE settings in your projects settings.py:

    DATABASES = {
        'default': {
            'ENGINE': 'django.db.backends.mysql',
            'NAME': '<database_name>',                    
            'USER': '<username>',     
            'PASSWORD': '<password>',
            'HOST':  r'<database server host name>',                      # Set to empty string for localhost.
        }
    }

Replace <database_name> with the name of your database (you should create this using MySQL Workbench or from the MySQL command line first if it doesn't exist).

Replace <username> and <password> with the username and password required to access your MySQL database (use the MySQL Grant command to grant permissions to the user with the password).

Replace <database server host name> with the name of the machine hosting the MySQL database or leave this empty if the MySQL database is on your local machine.

No comments:

Post a Comment