4

I am running python33 and I have installed pymysql3 but what ENGINE do I need to specify in the Django settings:

DATABASES = {
    'default': {
        'ENGINE': 'django.db.backends.mysql', # Add 'postgresql_psycopg2', 'mysql', 'sqlite3' or 'oracle'.
        'NAME': 'chris_test',                      # Or path to database file if using sqlite3.
        # The following settings are not used with sqlite3:
        'USER': 'some_user',
        'PASSWORD': 'some password',
        'HOST': 'some_host',                      # Empty for localhost through domain sockets or '127.0.0.1' for localhost through TCP.
        'PORT': '3306',                      # Set to empty string for default.
    }
}
4
  • Is there a reason that the standard django.db.backends.mysql can't be used? Why do you need Django to use PyMySQL? Commented Mar 13, 2013 at 19:26
  • Because I just can't get MySQLdb to install on my Windows box due to a cavalcade of incompatibilities and the bizarre notion (at least to a Windows user) that I should have to have a C compiler installed so that I can use a language that's supposed to be so much easier. Commented Mar 13, 2013 at 19:39
  • The C compiler is needed to compile the Python extensions. Working in Python is easy and great - but not always fast. For something as (purportedly) critical as a database client, you'd want it to be as fast as possible. Commented Mar 13, 2013 at 20:00
  • The django mysql connector /uses/ MySQLdb, which is now long dead. AFAIK there is no way to make django+python3 talk to mysql. Commented Jun 12, 2016 at 6:32

2 Answers 2

3

Look at django-mysql-pymysql for more info. Specifically,

'ENGINE': 'mysql_pymysql',

That was not enough for me though. I had to use this answer . If you have a foo Django app, then in your `foo/init.py', add the following:

import pymysql
pymysql.install_as_MySQLdb() 
Sign up to request clarification or add additional context in comments.

3 Comments

This does seem like the correct thing to do, although I'm not sure if django-mysql-pymysql is necessary (hasn't been maintained since 2012). From what I can tell, you should just be able to follow the instructions from that answer you pointed to.
PyMySQL was not my first choice, but I'd already started with Python 3 and need a solution now. I'm a bit aghast that the MySQL ecosystem is not ready for Python 3.
Several years now and this problem isn't solved. Seems like python 3 just doesn't do MySQL (or vice versa). I used this call to install pymysql as MySQLdb, and it finds it, and then barfs on missing "cannot import name 'Thing2Literal'". There are fixes, but it sure looks like good ol' mysql is dead to me.
1

Django already provides a MySQL backend. From looking at PyMySQL, it appears to be a general-purpose MySQL client. You can't arbitrarily use a different library in place of the existing Django backends; the APIs would be completely incompatible.

There is a project that appears to provide a Django backend that uses PyMySQL internally, but the author states that it is experimental, it has a total of 5 commits, and it hasn't been updated since 2012, so I wouldn't recommend trying to use it.

4 Comments

Thanks for that clarification... but as you may see from the comment above what I'm really trying to do is find a way that works because Django complains I don't have MySQLsb but attempting to install it merely complains about all kinds of issues and I can't find an installer for MySQLdb that actually works wioth Python33 on 64-bit windoes.
Take a look at this answer. It may have some suggestions. As far as it goes, MySQLdb isn't compatible with Python 3, so you'll have to use a different method if you want to stick with Python 3.
This "answer" is very unhelpful. It does not answer the question. I tried using Django's provided MySQL back end but found out that hard way that Python 3 is not supported. Other alternatives have other problems.
@JohnSchmitt: I wrote this answer in 2013; it turns out that install_as_MySQLdb() was available at that time, so the fix was likely possible, but at the least, the answer you pointed to hadn't been written yet.

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.