Quantcast
Channel: JS Tricks » Python
Viewing all articles
Browse latest Browse all 25

MySQL driver for Django Framework

$
0
0

While you are using Django Framework and want to use MySQL as the Database then sometime it will a bit problem for you. Because it is really tough to get a suitable MySQL driver for Django. And from Python 3 it has become more difficult.

In this lesson we will learn how to setup a suitable MySQL driver for Django Framework.

MySQL driver for Django Framework

mysql-connector-python is a MySQL driver which is written in Python and it does not depend on MySQL C client libraries.

When you are installing mysql-connector-python, ensure that you allow external hosted files like this:

pip install --allow-all-external mysql-connector-python

If you are behind a firewall then use the proxy option:

pip install --proxy my_proxy_server --allow-all-external mysql-connector-python

So now you have installed MySQL Driver for Django. And after this you can set your Django settings.py file with this MySQL Driver. Here is the code you should add in your settings.py file. Remember that you should replace any other Database configuration in your settings.py  file with this one for starting your Development in Django with MySQL Database.

DATABASES = {
    'default': {
        'ENGINE': 'mysql.connector.django',
        'NAME': 'mydb',
        'USER': 'myuser',
        'PASSWORD': 'mypassword',
    }
}

Here the NAME parameter is the name of your Database, USER parameter is the user of your Database and the PASSWORD parameter is the password for your Database user.

The post MySQL driver for Django Framework appeared first on JS Tricks.


Viewing all articles
Browse latest Browse all 25

Trending Articles