3

I'm learning Django with MySQL as backend. I installed Oracle's mysql connector to connect with mysql. However, when I run python manage.py I got this error

Traceback (most recent call last): File "C:\Python33\lib\site-packages\django\db\backends\mysql\base.py", line 14, in import MySQLdb as Database ImportError: No module named 'MySQLdb'

That's a bit weird. I was thinking if I installed mysql connector/python I dont need MySQLdb anymore.

Could anyone help explain? Thanks!

My database setting:

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

4 Answers 4

4
# for mysql connector use this

DATABASES = {
'default': {
    'ENGINE': 'mysql.connector.django',
    'NAME': 'dbname',               
    'USER': 'user',
    'PASSWORD': '',
    'HOST': '127.0.0.1',
    'PORT': '3306',
},

}

Sign up to request clarification or add additional context in comments.

1 Comment

mysql-connector-python, starting from version 8.0.13, has a bug, which makes it impossible to use with Django: code.djangoproject.com/ticket/30469 bugs.mysql.com/bug.php?id=92001 To avoid the bug, add option 'use_pure': True in the database options.
2

If you're using Oracle's connector, you need to use their Django db backend.

See their documentation.

1 Comment

Thanks! I also just saw it.
1

Try: pip install mysql-python

If that does not work: make sure you can connect to your database (use phpmyadmin or mysql workbench to test that)

Comments

1

try this for MySQL Connector that working in django:

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

or try this for MySQL Connector pool that working in django:

DATABASES = {
    'default': {
        'ENGINE': 'PyMysqlPool.mysql.connector.django',
        'NAME': 'djangolearn',
        'USER': 'root',
        'PASSWORD': '',
        'HOST': '127.0.0.1',
        'PORT': '3306',
        'OPTIONS': {
            'autocommit': True,
            'pool': {
                #use = 0 no pool else use pool
                "use":0,
                # size is >=0,  0 is dynamic pool
                "size":10,
                #pool name
                "name":"local",
            }
        },
    }
}

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.