[openstack-dev] [all] Replace mysql-python with mysqlclient

Victor Stinner vstinner at redhat.com
Thu Apr 30 15:00:24 UTC 2015


Hi,

I propose to replace mysql-python with mysqlclient in OpenStack applications to get Python 3 support, bug fixes and some new features (support MariaDB's libmysqlclient.so, support microsecond in TIME column).

The MySQL database is popular, but the Python driver mysql-python doesn't look to be maintained anymore. The latest commit was done in january 2014, before the release of MySQL-python 1.2.5:

   https://github.com/farcepest/MySQLdb1/commits/master

One major issue is that mysql-python doesn't support Python 3. It blocks porting most OpenStack applications to Python 3. There are now 32 open issues and 25 pending pull requests. I also sent an email to Andy Dustman (aka farcepest) last week, but I didn't get any reply yet.


There is an open discussion to replace mysql-python with PyMySQL, but PyMySQL has worse performance:

   https://wiki.openstack.org/wiki/PyMySQL_evaluation


Naoki INADA, the PyMySQL maintainer, forked mysql-python as the new project "mysqlclient". Quote of his email (part of long thread "[openstack-dev] [oslo] eventlet 0.17.3 is now fully Python 3 compatible"):

"""
I'm maintainer of PyMySQL and mysqlclient.

mysqlclient is fork of MySQL-python.  It uses libmysqlclient.so.
It fixes some bugs, build issues and it support Python 3. For example:

* Support MariaDB's libmysqlclient.so
* Support microsecond in TIME column

I recommend to use mysqlclient instead of MySQL-python even on Python 2.

https://pypi.python.org/pypi/mysqlclient
https://github.com/PyMySQL/mysqlclient-python
"""

Since mysqlclient is fork, it should have no impact on performances.

On PyPI, mysql-python and mysqlclient have a different name, but the Python module has the same name ("MySQLdb"). OpenStack code doesn't need to be modified, only dependencies.

mysqlclient is also tested in the "PyMySQL evaluation".

mysqlclient shares mysql-python drawbacks. It is implemented in C and it is not eventlet friendly (cannot be monkey-patched). A workaround is to run it in a thread or a thread pool.

I want to replace mysql-python with mysqlclient to get Python 3 compatibility in short term. We can reconsider PyMySQL later for other advantages like the ability to monkey-patch it. At the same time, there are also a deeper discussion to change how OpenStack handles concurrency (replace eventlet with threads, asyncio or something else):
https://review.openstack.org/#/c/164035/

Victor



More information about the OpenStack-dev mailing list