So I've been trying to do some database update with python and while setting up the whole dev environment, I came across these three things which made me dizzy.
There's MySQLdb
There's mysqlclient
What's each of them, the difference and where to use them? Thanks
MySQLdb is a thin python wrapper around C module which implements API for MySQL database.
There was MySQLDb1 version of wrapper used some time ago and now it is considered to be a legacy. As MySQLDb1 started evolving to MySQLDb2 with bug fixes and Python3 support, a MySQLDb1 was forked and here is how mysqlclient appeared, with bugfixes and Python3 support. Sum up, so now we have MySQLDb2 which is not ready for production use, MySQLDb1 as an outdated driver and a community supported mysqlclient with bug fixes and Python3 support.
Now, to solve that mess, MySQL provides their own version of MySQL adapter - mysql connector, an all-in python module that uses MySQL API with no C modules dependencies and only standard python modules used.
So now the question comes down to: mysqlclient vs mysql connector.
As for me, I would go with officially supported library, however mysqlclient
should be a good choice as well.
Both of them are being actively updated with fixes and new features which you can see by active commits in last days.
Note: I did not have much experience with them, so there might be cases when one or another does not suite your needs. Both libraries follow PEP-249 standard which means you should be fine with at least base functionality everywhere.
Installation and Dependencies
As a fork of C wrapper it requires C modules to work with MySQL which adds python header files to build these extensions (read python-dev). Installation depends on the system you use, just make sure you aware of package names and can install them.