MySQLdb
Python
Django
OSX 10.6
Database Integration

How to use MySQLdb with Python and Django in OSX 10.6?

System Design practice on Codemia

Work through 120+ system design problems with detailed solutions, from rate limiters to multi-region storage.

Practice system design

Introduction

On OSX 10.6, using Django with MySQL usually meant using the old MySQLdb driver from the MySQL-python package. The main challenge on Snow Leopard was not Django itself, but getting Python, MySQL client libraries, and the compiled extension to agree on architecture and library paths.

Understand What MySQLdb Means on This Stack

Historically, MySQLdb was the Python module provided by the MySQL-python package. In Django settings, you still point the backend at MySQL, but the actual DB-API driver loaded under the hood is MySQLdb.

On a legacy OSX 10.6 setup, the moving parts are:

  • Python 2.x
  • a local MySQL installation
  • development headers and mysql_config
  • the MySQL-python extension compiled for the same architecture as Python

If any of those disagree, installation usually fails with compiler or linker errors.

Install MySQL Client Libraries First

Before installing the Python package, make sure MySQL itself is installed and that mysql_config is available:

bash
which mysql_config
mysql_config --version
mysql_config --libs

If mysql_config is missing, the Python extension does not know where to find MySQL headers and libraries.

On an older machine, you may need to add the MySQL bin directory to your shell path:

bash
export PATH="/usr/local/mysql/bin:$PATH"

That does not solve everything, but it is a common first requirement.

Install MySQL-python for the Right Architecture

Snow Leopard often exposed 32-bit versus 64-bit mismatches. If Python is running as x86_64 and the MySQL client libraries are built differently, the extension build or import can fail.

Check your Python architecture:

bash
python -c "import platform; print(platform.architecture())"
python -c "import sys; print(sys.maxsize > 2**32)"

Then install the driver:

bash
ARCHFLAGS="-arch x86_64" pip install MySQL-python

If your environment is truly 32-bit, adjust the architecture flag accordingly. The exact fix depends on the binaries you have installed, but the principle is always the same: Python, MySQL client libraries, and the compiled extension must match.

If pip is not available on that machine, legacy setups sometimes used easy_install, but pip is easier to reason about if you can get it installed.

Configure Django to Use MySQL

Once the driver imports successfully, Django configuration is straightforward:

python
1DATABASES = {
2    "default": {
3        "ENGINE": "django.db.backends.mysql",
4        "NAME": "legacy_app",
5        "USER": "legacy_user",
6        "PASSWORD": "secret",
7        "HOST": "127.0.0.1",
8        "PORT": "3306",
9    }
10}

Then test the connection:

bash
python manage.py dbshell
python manage.py migrate

If Django starts and can connect, the Python driver is working.

Verify the Driver Directly

When debugging an old environment, verify the module before blaming Django:

bash
python -c "import MySQLdb; print(MySQLdb.__file__)"

You can also run a direct connection test:

python
1import MySQLdb
2
3conn = MySQLdb.connect(
4    host="127.0.0.1",
5    user="legacy_user",
6    passwd="secret",
7    db="legacy_app",
8    port=3306,
9)
10
11cursor = conn.cursor()
12cursor.execute("SELECT VERSION()")
13print(cursor.fetchone())
14conn.close()

If that fails outside Django, the issue is with the driver or MySQL libraries, not the ORM.

Modern Context

On current systems, mysqlclient replaced the old MySQL-python package. But for an OSX 10.6 era question, MySQLdb usually means working within an old Python 2 and Django stack where MySQL-python was the expected answer.

That matters because many modern installation guides assume newer compilers, newer OpenSSL, and Python 3, which do not map cleanly onto Snow Leopard.

Common Pitfalls

The most common failure is an architecture mismatch between Python and the MySQL client libraries. On older macOS versions, that problem appears often and produces confusing build errors.

Another issue is missing mysql_config. Without it, the extension cannot locate the headers and libraries required during compilation.

Developers also sometimes configure Django correctly but never test whether import MySQLdb works on its own. That wastes time because the import step is usually where the root problem lives.

Finally, keep the legacy context in mind. Advice for mysqlclient on modern Python 3 is useful in general, but it is not a drop-in fix for OSX 10.6.

Summary

  • On OSX 10.6, MySQLdb usually comes from the MySQL-python package.
  • Install MySQL first and make sure mysql_config is on your path.
  • Match the architecture of Python, MySQL libraries, and the compiled extension.
  • Verify import MySQLdb before debugging Django settings.
  • In Django, use django.db.backends.mysql and test the connection with management commands.

Related reading
Course
Beginner
27 lessons
10 hours
System Design Fundamentals

Build a strong foundation in designing scalable, reliable distributed systems.

View the course
Track what you have practised

A free account saves your progress, solutions and study plan across every problem on Codemia.

System Design practice on Codemia

Work through 120+ system design problems with detailed solutions, from rate limiters to multi-region storage.

Practice system design

All Rights Reserved.