Python, Django, & MySQL on Windows 7, Part 5: Installing MySQL

This is the fifth and final post in a  dummies guide to getting stared with Python, Django, & MySQL on Windows 7.

By now, you should have Django installed into a virtual environment.  These tutorials aren’t meant to cover building a django app, just to point out the quirks involved with getting a project up and running on Windows.  These tutorials also assume you want to construct real applications using a real development environment.

To that end, you’ll want a heftier database than sqlite.  We use MySQL at the office, so these instructions cover installing it and using it with Django.

Install MySQL

  1. Download and install MySQL.
  2. Once MySQL is installed, proceed through the configuration wizard. Check Include Bin Directory in Windows PATH box.
  3. When prompted, set a password for the MySQL root account.
  4. Once the installation wizard is done, open a command window and log in to MySQL with the root account: mysql -uroot -p (you’ll be prompted for the password).
  5. After logging in, run the following commands to create a database, create a user for your Django project, and grant the user database access.

Install MySQL-python

You’ll need the MySQL-python package, a Python interface to MySQL.

  1. Download the windows MySQL-python distribution here.  The author has some instructions about the appropriate version; assuming a 32-bit version of Python 2.7, you’d download this package (.exe).
  2. After downloading, do not run the Windows installer. Doing so will install MySQL-python to your root python, which virtual environments created via –no-site-packages won’t be able to see.
  3. Instead, install the downloaded package to your virtual environment by using easy_install, which can install from Windows binary installers:
    easy_install file://c:/users/you/downloads/mysql-python-1.2.3.win32-py2.7.exe (modify to reflect the location of the downloaded installer and its name).installing mysql-python package via easy_install

Configure Django

Next, you’ll need to update the database-related settings of your Django project.

  1. From the directory of your Django project, open using your favorite editor.
  2. Update the default key in the DATABASES dictionary.  Set ENGINE to django.db.backends.mysql and set NAME, USER, and PASSWORD to the database name, username, and password you chose when installing MySQL.  See Part I of the Django tutorial for more information about database settings.
  3. Open a command window, activate your virtual environment, and change to the directory of your Django project.
  4. Type python syncdb. This command creates the underlying tables required for your Django project.
    syncdb output
  5. If the syncdb worked, you have Python, Django, and MySQL communicating in harmony.  Congratulations!  You can now proceed through the Django tutorial and create your first application.

, , ,

19 Responses to Python, Django, & MySQL on Windows 7, Part 5: Installing MySQL

  1. João Paulo Dubas May 25, 2012 at 8:18 am #

    Thanks for your tips, specially on using `easy_install` to install the MySQL-python from the exe file.

    This saved me a lot of time.

  2. JukkaN January 16, 2013 at 8:55 pm #

    This was massively helpful, thanks a ton.

    I used this method to install setuptools (preferable to the registry hack):

    Also, I had to use ‘django.bin.django-admin’ instead of ‘django-admin’ in the startproject command

    Also, took me time to realize I had to replace ‘django.*’ with ‘mydatabasename.*’ in this command:
    ‘GRANT ALL ON django.* TO ‘django_user’@’localhost’

  3. LoveTheInternet October 5, 2013 at 10:44 am #

    GRANT ALL ON django.* TO ‘django_user’@’localhost’

    Should have a semicolon at the end

  4. Becky October 9, 2013 at 6:44 pm #

    Thanks, JukkaN and LoveTheInternet for the helpful feedback/corrections. I made your suggested changes–they will help the next person who comes along!

  5. Noyt June 20, 2014 at 8:22 pm #

    HUGE thanks, I read many other tutorials for installing django+mysql on windows, but this is the only one that works.

    Although I did hit a minor problm with the last section at “python syncdb” -where i got a NameError [dbname] is not defined. Solved by simply starting from the begining of part 5 and creating a new DB, user and re-editing with the new details. also re-started the virtual enviroment and re-imported django.

    also check that when you edit, it’s saved as ‘’ and not ‘’

  6. Sreeharinath March 30, 2015 at 9:07 am #

    This is the only solution for Configuration of Mysql , Pyhton and Django

    Connectivity between Django and Python in was complex in Windows 8

    This solved me the issue

    But make sure to download correct version 64 32 bit of your python version not OS

    Thanks a ton Becky


  7. Ivan May 21, 2015 at 11:28 pm #

    You are the best, really, man! I`v wasted almost day configuring DB. Thanks man)

  8. Nuno October 13, 2015 at 6:50 am #

    Thanks! This solved my problem, because i couldn’t find another solution on the Internet for this.

  9. Himanshu November 1, 2017 at 3:41 am #

    Instead of python syncdb, we should use python migrate.
    syncdb command is deprecated in django 1.7.

  10. Anirudh March 9, 2018 at 7:27 am #

    Thanks a ton for your amazing tutorial!!. There have been some changes since the time you have made this tutorial. syncdb has been deprecated. In place of ‘syncdb’, we will use ‘python migrate’.

  11. Himanshu December 7, 2018 at 3:48 am #

    It showed couldn’t find the syncdb command. Am I missing something?


  1. Python, Django, & MySQL on Windows 7, Part 3: iPython & Virtual Environments | Computers are for People - September 14, 2011

    […] Part 5: installing MySQL […]

  2. Python, Django, & MySQL on Windows 7, Part 2: Virtual Environments | Computers are for People - September 14, 2011

    […] Part 5: installing MySQL […]

  3. Python, Django, & MySQL on Windows 7, Part 1: Installing Python, Pip, and iPython | Computers are for People - September 14, 2011

    […] Part 5: installing MySQL […]

  4. Python, Django, & MySQL on Windows 7, Part 4: Installing Django | Computers are for People - September 15, 2011

    […] Part 5: installing MySQL We’re finally ready to install Django, a popular Web-development framework. Detailed instructions for building out a Django site are beyond the scope of this humble tutorial; try The Definitive Guide to Django or Django’s online Getting started docs for that. […]

  5. Python, Django, MySQL & Win 7 | Computers are for People - January 29, 2012

    […] Part 5: installing MySQL Parting thoughts: […]

  6. Installing MySQL, Python and Django on Windows | andersguide - April 3, 2013

    […]… […]

  7. Installing Django: Using XAMPP's MySQL, MySQL-python 1.2.3 & 1.2.4 errors? | BlogoSfera - July 13, 2013

    […] am following this awesome walk-through on how to install […]

  8. Django in Google App Engine and Cloud SQL | Mixed channel - June 1, 2014

    […] We need install mysql driver to our virtual python environment in c:penv_gaeenv.  Unfortunately installation package cannot do this automatically, so we need some tricks (good article here) […]

Leave a Reply