環境:Python 3.5+, Django 1.9+
最初用django時,搜索時發現PyMySQL的文章很多,然而在django的官方文檔中python3版的mysql客戶端驅動確沒有提到PyMySQL,只提到了mysqlclient,再細看下去發現:
1. 兩個庫的作者是同一個人INADA Naoki, pip庫郵箱都指向mailto:songofacandy@gmail.com
2. PyMySQL的代碼人員methane說mysqlclient速度更快及PyMySQL的應用場景,參見:https://github.com/PyMySQL/PyMySQL/issues/342
mysqlclient-python is much faster than PyMySQL.
When to use PyMySQL is:
- You can't use libmysqlclient for some reason
- You want to use monkeypatched socket of gevent or eventlet
- You wan't to hack mysql protocol
3. Django1.9.12官方文檔中:
Django requires mysqlclient 1.3.3 or later. Note that Python 3.2 is not supported. Except for the Python 3.3+ support,
mysqlclient should mostly behave the same as MySQLDB.
4. https://python.libhunt.com/project/mysqlclient-python/vs/pymysql 兩者基本面的對比
經上對比,准備先用mysqlclient!