如何通过pip安装mysql连接器

2024-06-25 23:26:33 发布

您现在位置:Python中文网/ 问答频道 /正文

我在Python项目中使用sqlalchemy访问MySQL。sqlalchemy的配置如下:

dialect=mysql
driver=mysqlconnector

所以我需要通过pip安装Python模块mysql连接器。有什么帮助吗?


Tags: 模块pip项目sqlalchemydrivermysqldialectmysqlconnector
3条回答

如果通过pip install mysql-connector加载并导致错误Unable to find Protobuf include directory,那么这将非常有用pip install mysql-connector==2.1.4

mysql-connector已过时,因此请使用pip install mysql-connector-pythonSame here

pip install mysql-connector

最后,也可以通过源代码安装mysql连接器

从以下位置下载源代码: https://dev.mysql.com/downloads/connector/python/

要安装Python的MySQL官方连接器,请使用名称mysql-connector-python

pip install mysql-connector-python

进一步讨论,当我们此时(2018年11月)对mysql-connector进行pip search时,最相关的结果如下:

$ pip search mysql-connector | grep ^mysql-connector
mysql-connector (2.1.6)                  - MySQL driver written in Python
mysql-connector-python (8.0.13)          - MySQL driver written in Python
mysql-connector-repackaged (0.3.1)       - MySQL driver written in Python
mysql-connector-async-dd (2.0.2)         - mysql async connection
mysql-connector-python-rf (2.2.2)        - MySQL driver written in Python
mysql-connector-python-dd (2.0.2)        - MySQL driver written in Python
  • PyPI上提供了mysql-connector (2.1.6),而MySQL一开始没有在PyPI上提供官方的pip install(这很不方便)。但它是一个fork,并且停止更新,所以

    pip install mysql-connector
    

    将安装此过时版本。

  • 现在PyPI上的mysql-connector-python (8.0.13)是MySQL维护的官方包,所以我们应该安装这个包。

相关问题 更多 >