When using Django for developing a web applications, it’s common to use MySQL as a data repository.
In order to use this combination of technolgies, one needs to setup all the different pieces. Setting up all this may not be as easy as it may seem and it actually will take a bit longer than one may expect.
To ease this process, here’s a simple step-by-step guide to help seting a Django with MySQL development environment.
The first step is to download and install Python. Current Django version, 1.3, does not work on Python 3, so download the latest Python 2 version, presently 2.7.2, or use your system package manager to get it from the official repository.
The second step is to download and install MySQL.
Check your system package manager to get it from the official repository, if available.
Don’t try to use Xampp. It may work but you’ll have to hack some installation procedures, specially in Windows 64 bit. For instance, the database connector will look up the MySQL location in the Windows registry and it will be missing.
I recommend the MySQL bundle, since it will come with useful software for database management.
Finally, we need to download the MySQL-Python connector so that we can use MySQL from Python.
Uncompress the file and, on a shell, perform the standard installation procedure: python setup.py install. Depending on your system, you may need to run this with administration privilidges.
If you’re using Windows, I seriously recommend that you download and install codegood build. If you don’t wish to use codegood build and are getting file not found errors originated from a registry key not found – usually in 64 bit versions – just edit the site.cfg file with a plain text editor and change the registry_key to “SOFTWARE\Wow6432Node\MySQL AB\MySQL Server 5.5“, in 64 bit, taking in consideration that the version numbers should correspond to your MySQL installed version. When in doubt, use Windows Registry application, regedit.exe, to check the correct registry key.
Optionally, if you’re installing on Windows, I recommend you to install MSYS and to run the Django commands from this shell.
This will enable you a linux like shell that is helpful to process some commands like localization, e. g. the gettext tool. If you don’t wish to install MSYS, check the Django documentation on how to get the required tools to work on Windows.
Since all the technologies are always under development, make sure you get the right versions of each so that things work properly.
After following these steps, Python should connect to MySQL, and so should Django.