Django connecting to MySQL via Mysql-connector fails

28 views
Skip to first unread message

Jerry Xue

unread,
Sep 23, 2014, 8:56:02 AM9/23/14
to django...@googlegroups.com
Hi, I'm learning django with PyDev, MySQL as backend. According to doc I used Oracle's MySQL connector to communicate with db:

The Python Database API is described in PEP 249. MySQL has two prominent drivers that implement this API:

  • MySQLdb is a native driver that has been developed and supported for over a decade by Andy Dustman.
  • MySQL Connector/Python is a pure Python driver from Oracle that does not require the MySQL client library or any Python modules outside the standard library.

Both drivers are thread-safe and both provide connection pooling. The major difference is that MySQL Connector/Python supports Python 3.

However I got this error when I ran manage.py migrate in PyDev.

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

I checked the basefile it only imports MySQLdb.

try:
    import MySQLdb as Database
except ImportError as e:
    from django.core.exceptions import ImproperlyConfigured
    raise ImproperlyConfigured("Error loading MySQLdb module: %s" % e)

Below is my settings:

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

What's wrong here? Does it mean I need MySQLdb to use MySQL connector?

Thanks!

Collin Anderson

unread,
Sep 23, 2014, 2:44:54 PM9/23/14
to django...@googlegroups.com
You need to use "mysql.connector.django" as your backend ENGINE

Reply all
Reply to author
Forward
0 new messages