1

I've read so many articles, I'm blind, but I'm sure to one of you this will be simple...

I have setup a VPS on MyHosting running Ubuntu 12.04. Try as I might, I can't get MySQL running with Django. When I run python3 manage.py migrate I get an error ending with:

ImproperlyConfigured: Error loading MySQLdb module: No module named MySQLdb

I got to this point by:

sudo apt-get install python3
sudo apt-get install python3-setuptools
sudo easy_install3 pip
sudo pip3 install django

The above installed Python 3.2.3 django version: 1.8.4 mysql version: Ver 14.14 Distrib 5.5.44

I edited settings.py to include the following:

DATABASES = {
    'default': {
    'NAME': 'user_data',
        'ENGINE': 'mysql.connector.django',
        'USER': 'mysql_user',
        'PASSWORD': 'priv4te',
        'OPTIONS': {
          'autocommit': True,
        },
    }
}

PS Apache version: Apache/2.2.22

Jon
  • 97
  • 9
  • PS I also tried configuring the database ENGINE option to django.db.backends.mysql – Jon Sep 04 '15 at 15:38
  • 4
    You need to install the MySQL-Python package: http://stackoverflow.com/a/29150749/240418 – girasquid Sep 04 '15 at 15:40
  • Forgot to say that I tried that. Just tried again: pip3 install MySQL-python ImportError: No module named ConfigParser – Jon Sep 04 '15 at 16:15
  • Sounds like it doesn't support Python 3: http://stackoverflow.com/a/14087705/240418 – girasquid Sep 04 '15 at 16:27

2 Answers2

1

The Django docs recommend you use mysqlclient, a Python 3 compatible fork of MySQLDB.

You should be able to install it with:

pip3 install mysqlclient

It might be better to use a virtualenv, in which case you can use pip instead of pip3 in the virtualenv.

pip install mysqlclient

Your databases backend should be django.db.backends.mysql.

However, mysqlclient requires Python 3.3+ for Python 3. If you want to run Django with MySQL, I believe your options are currently either Python 2.7 or 3.3+.

Alasdair
  • 298,606
  • 55
  • 578
  • 516
  • I ran pip3 install mysqlclient successfully, and it installed version 1.3.6 But when I then tried python3 manage.py migrate I got this error: ImproperlyConfigured: Error loading MySQLdb module: /usr/local/lib/python3.2/dist-packages/_mysql.cpython-32mu.so: undefined symbol: PyUnicode_AsUTF8 – Jon Sep 04 '15 at 16:31
  • Ah, it looks like mysqlclient [isn't compatible](http://stackoverflow.com/questions/31414327/django-undefined-symbol-pyunicode-asutf8) with Python 3.2. Is it possible to upgrade to Ubuntu 14.04 with Python 3.4? Otherwise, using 12.04 with Python 2.7 might be easiest. – Alasdair Sep 04 '15 at 16:34
  • I'll try uninstalling Python3 (and I guess Django, too) – Jon Sep 04 '15 at 16:39
0

Try

    pip install MySQL-python

If you receive error mysql_config not found

Run

    sudo apt-get install python-mysqldb
Tevin Joseph K O
  • 2,574
  • 22
  • 24