Python3 + MySql: Error loading MySQLdb module: No module named ‘MySQLdb’

I am new to Python and trying to setup a Django project to work with MySql. I have read through the documentation as well as some other StackOverflow posts about the topic, but I still can’t get it to work.

When I try to run a migrate in Django I get the following error:

Error loading MySQLdb module: No module named 'MySQLdb'

I have installed the recommended MySql Python Connector (2.0.1) selecting Ubuntu (since I am on Mint Linux). It installs correctly. I still get the error. I don’t need to add this library to the project or anything, right? It looks like python should just be aware of this and run successfully. What can I do? Thanks.

EDIT: I forgot to mention: I am running Python 3.4 – a lot of typical solutions are still using 2.7, so they don’t work and all the solutions with 3.0 I have tried without success.


Thank you for visiting the Q&A section on Magenaut. Please note that all the answers may not help you solve the issue immediately. So please treat them as advisements. If you found the post helpful (or not), leave a comment & I’ll get back to you as soon as possible.

Method 1

None of the existing answers worked for me on Ubuntu Server 16.04 so I ran:

sudo apt-get install libmysqlclient-dev
sudo -H pip3 install mysqlclient

The first command get me the mysql config needed by the second command.

Method 2

pip install mysqlclient
works for me python3.5

Method 3

I would need to see your DATABASES configuration in, but it looks like it is trying to load MySQLDB instead of the Mysql Python Connector that you installed. The DATABASES should look something like this:

    'default': {
        'NAME': 'mydatabase',
        'ENGINE': 'mysql.connector.django',
        'USER': 'myuser',
        'PASSWORD': 'secretpassword',
        'OPTIONS': {
          'autocommit': True,

Note the ENGINE part… that tells Django to use the mysql connector instead of MySQLDB…

more info available here:

and if you are expecting to use South:

You may want to note that the Oracle connecter is GPL, and there may be license issues with using that code. See Here:!topic/django-developers/8r_RVmUe5ys

The Django 1.7 documentation recommends using the mysqlclient driver…
–see the section on Mysql DB API Drivers for that client…


Method 4

If you can install pymysql — which works well for me with Python 3.4 — then add these lines to your file in Django:

    import pymysql
except ImportError:

This will make pymysql function like MySQLdb and worked for me.

All methods was sourced from or, is licensed under cc by-sa 2.5, cc by-sa 3.0 and cc by-sa 4.0

0 0 votes
Article Rating
Notify of

Inline Feedbacks
View all comments
Would love your thoughts, please comment.x