12

I'm running Mac OSX 10.9 Mavericks. I'm trying to run django under python 3. Because I'm running Python 3 I have to get the official connector from the mysql devs here gave it a quick test in the shell and it works.

I ran python manage.py runserver with "mysql.connector.django" as the engine having seen an example here and I got this error:

django.core.exceptions.ImproperlyConfigured: 'mysql.connector.django' isn't an available database backend.
Try using 'django.db.backends.XXX', where XXX is one of:
u'mysql', u'oracle', u'postgresql_psycopg2', u'sqlite3'
Error was: No module named mysql.connector.django.base

So I switch back to the default using "django.db.backends.mysql" as my engine and I get this error:

django.core.exceptions.ImproperlyConfigured: Error loading MySQLdb module: No module named MySQLdb

I have no idea how to proceed. I can't install MySQLdb because I'm running my django install under python3 and it's unsupported, but I'm definitely missing something with this connector.

Iteria
  • 421
  • 1
  • 5
  • 13
  • 1
    http://stackoverflow.com/questions/454854/no-module-named-mysqldb – Priyank Patel Mar 15 '14 at 04:06
  • possible duplicate of [Python 3 and mysql](http://stackoverflow.com/questions/4960048/python-3-and-mysql) – Bibhas Debnath Mar 15 '14 at 06:04
  • [Priyank's suggestion](http://stackoverflow.com/questions/454854/no-module-named-mysqldb) combined with [this](http://stackoverflow.com/questions/6383310/python-mysqldb-library-not-loaded-libmysqlclient-18-dylib) solved the problem. thanks! – Iteria Mar 15 '14 at 20:21

1 Answers1

18

For python 2.7, 3.3+ there is a driver called mysqlclient that works with django 1.8

pip install mysqlclient

And in your settings

DATABASES = {
    'default': {
        'NAME': '',
        'ENGINE': 'django.db.backends.mysql',
        'USER': '',
        'PASSWORD': '',      
    }
}

Here's the official django documentation about the mysql drivers:

https://docs.djangoproject.com/en/1.8/ref/databases/#mysql-db-api-drivers

alejandrodnm
  • 5,410
  • 3
  • 26
  • 28
  • To get this to work I had to add a symlink to libmysqlclient. [http://stackoverflow.com/questions/6383310/python-mysqldb-library-not-loaded-libmysqlclient-18-dylib](http://stackoverflow.com/questions/6383310/python-mysqldb-library-not-loaded-libmysqlclient-18-dylib) – None May 18 '15 at 23:57
  • 1
    I have spent nearly a day trying to get this to work - and this has been the only solution to resolve the issue! [+] – Thomas Kimber Aug 10 '15 at 12:53
  • I get the error when installing via pip3: `OSError: mysql_config not found` – nerdoc Apr 19 '17 at 09:04
  • I still can't get this to work... I'm using ```'ENGINE': 'django.db.backends.mysql',``` pip freeze: asgiref==3.2.3 Django==3.0 django-mysql==3.3.0 dnspython==1.16.0 mysql-connector-python==8.0.19 mysqlclient==1.4.6 protobuf==3.6.1 PyMySQL==0.9.3 pyodbc==4.0.28 pytz==2019.3 six==1.14.0 sqlparse==0.3.0 I'm still getting the same Error: ```django.core.exceptions.ImproperlyConfigured: 'django.db.backends.mysql' isn't an available database backend.``` –  Feb 19 '20 at 04:21