django-mysql
Django-MySQL extends Django's built-in MySQL and MariaDB support their specific features not available on other databases.
What it is and what it does
Django-MySQL is a bridge library that unlocks MySQL and MariaDB capabilities within Django's ORM that would otherwise be unavailable. It provides QuerySet extensions for efficient pagination and approximate counting, specialized model fields like MariaDB Dynamic Columns and comma-separated fields, direct access to over 20 MySQL-specific SQL functions, and utilities for database-level operations like named locks and table management.
The package is designed for Django projects that have committed to MySQL or MariaDB and want to leverage database-specific optimizations and features. It integrates directly into Django's model and queryset layers, so usage typically involves importing custom field classes or manager methods rather than learning a separate API. The library maintains compatibility with current Django versions (4.2 through 6.0) and modern Python (3.9+), with no external compiled dependencies beyond what Django itself requires.
Use it for:
- Optimize pagination on large querysets using chunked iteration instead of loading all results into memory.
- Get quick row count estimates using approx_count instead of expensive COUNT(*) queries on massive tables.
- Store semi-structured data like configuration dictionaries using MariaDB Dynamic Columns without a separate JSON column.
- Implement application-level locking on shared resources using MySQL named locks without external lock services.
- Leverage MySQL-specific functions like JSON operations or string functions directly in ORM expressions.
Worth the install?
AI-flagged interpretation of the facts on this page — verify before relying
Django-MySQL extends Django's ORM with MySQL and MariaDB-specific features including QuerySet optimizations, specialized model fields, MySQL functions, and database utilities not available in Django's generic database layer.
Yes, if your Django project uses MySQL or MariaDB and you need database-specific optimizations or features. The package is actively maintained, has no known vulnerabilities, carries a permissive MIT license, and integrates cleanly with current Django versions. Install friction is minimal. If you use PostgreSQL or SQLite, this package provides no value.
Install
django-mysql on PyPI
pip
pip install django-mysqluv
uv add django-mysqlpoetry
poetry add django-mysqlInstalling django-mysql
Before you install
Low install friction with a single pure-Python wheel dependency on django. Actively maintained with recent commits and a stable production release status across Django 4.2 through 6.0 and Python 3.9 through 3.14.
License in practice
MIT license permits free use, modification, and distribution with minimal restrictions, making it suitable for both open-source and commercial projects.
Quickstart
pip install django-mysql
from django_mysql.models import QuerySet
from django.db import models
class MyModel(models.Model):
objects = QuerySet.as_manager()
class Meta:
db_table = 'my_table'
Requires Django and MySQL/MariaDB as the project database; features are only available when using MySQL or MariaDB, not other database backends.
Verify before relying
- Whether approx_count performance gains are significant for typical table sizes in production environments.
- Compatibility guarantees with MySQL versions beyond those explicitly tested in CI.
- Performance characteristics of the MySQL upsert-based cache backend compared to standard Django cache backends.
Package facts
| License | MIT (permissive) |
| Python support | supports the current Python release (>=3.9) |
| Install friction | low — pure-Python wheel |
| Runtime dependencies | 1 — django |
| Maintenance | actively maintained — 330 days since the last release |
| Last repo commit | |
| First released | |
| Downloads | 742,761/month — #5,179 on PyPI (30-day window, as of 2026-08-14) |
| Known vulnerabilities | none known (OSV.dev, checked 2026-08-14) |
Evidence: django_mysql-4.19.0-py3-none-any.whl
Keywords: Django, MariaDB, MySQL
Tags
More Database packages
psycopg2-binary is a PostgreSQL database…
copyleft · top 1,000 on PyPI
redisPython client library for connecting to and…
permissive · top 1,000 on PyPI
ydbYDB Python SDK is the official client library…
permissive · top 1,000 on PyPI
snowflake-connector-pythonConnects Python applications to Snowflake data…
permissive · top 1,000 on PyPI
sqlparsesqlparse tokenizes SQL text into a tree of…
permissive · top 1,000 on PyPI
dbt-adaptersProvides base adapter protocols and shared…
permissive · top 1,000 on PyPI
PyMySQLPyMySQL is a pure-Python MySQL and MariaDB…
permissive · top 1,000 on PyPI
peeweePeewee is a lightweight ORM that maps Python…
unclear · top 1,000 on PyPI
mysqlclientmysqlclient provides a Python interface to…
copyleft · top 1,000 on PyPI
ponyPony is an object-relational mapper that lets…
permissive · top 15,000 on PyPI
django-jsonfieldProvides a JSONField for Django models that…
permissive · top 15,000 on PyPI
django-cteAdds Common Table Expressions (CTE) support to…
permissive · top 5,000 on PyPI
django-tree-queriesQuery hierarchical tree structures in Django…
permissive · top 15,000 on PyPI
modelsearchIndexes Django models into Elasticsearch,…
permissive · top 15,000 on PyPI
mariadbMariaDB Connector/Python provides a DB API…
copyleft · top 15,000 on PyPI
djfernetProvides Fernet symmetric encryption for Django…
permissive · top 15,000 on PyPI