Search code examples
mysqldjangomysql-connector-pythonlibmysqlclient

How can I connect an up-to-date django server to a MySQL 5.1 database? (upgrading the MySQL version is not an option)


I have a MySQL-server that is part of a software system that is not developed by me. Thus it is not possible for me to upgrade that MySQL-server to a newer version, because it might break the software system's ability to interact with that database.

I need read access to that database on my public facing django application. The django version is the latest LTS (4.2).

Django's documentation lists two database API driver options for MySQL:

  1. mysqlclient
  2. MySQL Connector/Python

Both of these in their most current versions do not support access to MySQL 5.1 servers

Option 1. still works on Debian 11, with some overwritten methods in a subclass, but not on Debian 12.

How do I ensure that my django application still works, when I upgrade its production server from Debian 11 to 12?

I have tried using MySQL Connector/Python with the option use_pure, but it gives me the error django.db.utils.DatabaseError: (1193, "1193 (HY000): Unknown system variable 'default_storage_engine'", 'HY000').

I am unsure what I would have to patch, when subclassing that, in order to restore compatibility with MySQL 5.1.


Solution

  • I found a solution for my specific use-case. It boils down to subclassing django's mysql database backend (django.db.backends.mysql) and adapting the parameters it passes to mysqlclient (MySQLdb.connect) when connecting to the legacy MySQL-server.