Tuesday, September 23, 2014

Django connecting to MySQL via Mysql-connector fails

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!

--
You received this message because you are subscribed to the Google Groups "Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to django-users+unsubscribe@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at http://groups.google.com/group/django-users.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/cac94278-d1bf-43d0-b6d6-152955c2cede%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

No comments:

Post a Comment