Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to make Django work with unsupported MySQL drivers such as gevent-mysql or Concurrence's MySQL driver?

I'm interested in running Django on an async framework like Concurrence or gevent. Both frameworks come with its own async MySQL driver.

Problem is Django only officially supports MySQLdb. What do I need to do to make Django work with the MySQL drivers that come with gevent or Concurrence?

Is there a step-by-step guide somewhere that I can follow? Is this a major undertaking?

Thanks.

like image 769
Continuation Avatar asked Apr 14 '10 10:04

Continuation


1 Answers

three cheers for @traviscline's suggestion to go with pymysql. his suggestion was based on this post from mozilla. all it takes is a simple patch to your manage.py file

#!/usr/bin/env python
+try:
+    import pymysql
+    pymysql.install_as_MySQLdb()
+except ImportError:
+    pass 

changing the import in your settings file, and monkeypatch() since pymysql is a pure python driver.

travis mentioned that he tests for compatability by changing the imports and running the unittests for pymysql, mysqldb, and myconnpy.

note that there are already examples of finer details to watch out for - but overall this is an elegant, maintainable solution. i will update when i get this running in production!

like image 187
egbutter Avatar answered Nov 08 '22 01:11

egbutter