No module named MySQLdb

0 votes
asked Jan 18, 2009 by jbcedge

I am using Python version 2.5.4 and install MySQL version 5.0 and Django. Django is working fine with Python, but not MySQL. I am using it in Windows Vista.

15 Answers

0 votes
answered Jan 18, 2009 by evan-fosmark

mysqldb is a module for Python that doesn't come pre-installed or with Django. You can download mysqldb here.

0 votes
answered Jan 18, 2009 by daniel-lopez

If you are running on Vista, you may want to check out the Bitnami Django stack. It is an all-in-one stack of Apache, Python, MySQL, etc. packaged with Bitrock crossplatform installers to make it really easy to get started. It runs on Windows, Mac and Linux. Oh, and is completely free :)

0 votes
answered Jan 3, 2011 by derevo

You need to use one of the following commands. Which one depends on what OS and software you have and use.

  1. easy_install mysql-python (mix os)
  2. pip install mysql-python (mix os)
  3. apt-get install python-mysqldb (Linux Ubuntu, ...)
  4. cd /usr/ports/databases/py-MySQLdb && make install clean (FreeBSD)
  5. yum install MySQL-python (Linux Fedora, CentOS ...)

For Windows, see this answer: Install mysql-python (Windows)

0 votes
answered Jan 14, 2011 by panckreous


sudo apt-get install python-mysqldb
0 votes
answered Jan 4, 2012 by afshin-mehrabani

Thanks to derevo but I think there's another good way for doing this:

  1. Download and install ActivePython
  2. Open Command Prompt
  3. Type pypm install mysql-python
  4. Read the notes specific to this package.

I think pypm is more powerful and reliable than easy_install.

0 votes
answered Jan 24, 2014 by janek-olszak

...and remember there is no MySQLdb for python3.x

(I know the question is about python2.x but google rates this post quite high)

EDIT: As stated in the comments, there's a MySQLdb's fork that adds Python 3 support:

0 votes
answered Jan 2, 2015 by grvtyagi
  • Go to your project directory with cd.
  • source/bin/activate (activate your env. if not previously).
  • Run the command easy_install MySQL-python
0 votes
answered Jan 28, 2015 by venkat-kotra

If you are on a virtual environment then

pip install MySQL-python
0 votes
answered Jan 3, 2016 by alfred-huang

I met the same situation under windows, and searched for the solution.

Seeing this post Install mysql-python (Windows).

It points out installing such a pip environment is difficult, needs many other dependencies.

But I finally know that if we use mysqlclient with a version down to 1.3.4, it don't need that requirements any more, so try:

pip install mysqlclient==1.3.4
0 votes
answered Jan 11, 2016 by goksel

if your python version is 3.5, do a pip install mysqlclient, other things didn't work for me

Welcome to Q&A, where you can ask questions and receive answers from other members of the community.
Website Online Counter