Python 如何通过pip安装mysql-connector

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/32754461/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-19 12:11:23  来源:igfitidea点击:

How to install mysql-connector via pip

pythonsqlalchemymysql-connector

提问by Codefor

I use sqlalchemy to access MySQL in my Python project. sqlalchemy's conf is like this:

我使用 sqlalchemy 在我的 Python 项目中访问 MySQL。sqlalchemy 的 conf 是这样的:

dialect=mysql
driver=mysqlconnector

So I need to install the Python module mysql connector via pip. Any help?

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

回答by Codefor

pip install mysql-connector

Last but not least,You can also install mysql-connector via source code

最后但并非最不重要的一点,您还可以通过源代码安装 mysql-connector

Download source code from: https://dev.mysql.com/downloads/connector/python/

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

回答by Zaheer Khorajiya

execute following command from your terminal

从终端执行以下命令

sudo pip install --allow-external mysql-connector-python mysql-connector-python

回答by Partha Sen

If loading via pip install mysql-connectorand leads an error Unable to find Protobuf include directorythen this would be useful pip install mysql-connector==2.1.4

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

mysql-connectoris obsolete, so use pip install mysql-connector-python. Same here

mysql-connector已过时,因此请使用pip install mysql-connector-python. 同样在这里

回答by user2459835

First install setuptools

首先安装setuptools

sudo pip install setuptools

Then install mysql-connector

然后安装mysql-connector

sudo pip install mysql-connector

If using Python3, then replace pip by pip3

如果使用 Python3,则将 pip 替换为 pip3

回答by Umesh Yadav

For Windows

对于 Windows

pip install mysql-connector

pip 安装 mysql 连接器

For Ubuntu /Linux

对于 Ubuntu /Linux

sudo apt-get install python3-pymysql

须藤 apt-get 安装 python3-pymysql

回答by YaOzI

To install the officialMySQL Connector for Python, please use the name mysql-connector-python:

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

pip install mysql-connector-python


Some further discussion, when we pip searchfor mysql-connectorat this time (Nov, 2018), the most related results shown as follow:

一些进一步的讨论,当我们pip searchmysql-connector在这个时候(NOV,2018),显示如下的最相关的结果:

$ 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
  • mysql-connector (2.1.6)is provided on PyPI when MySQL didn't provide their official pip installon PyPI at beginning (which was inconvenient). But it is a fork, and is stopped updating,so

    pip install mysql-connector
    

    will install this obsolete version.

  • And now mysql-connector-python (8.0.13)on PyPI is the official package maintained by MySQL, so this is the one we should install.

  • mysql-connector (2.1.6)当 MySQL 一开始没有pip install在 PyPI 上提供他们的官方信息时(这很不方便),它在 PyPI 上提供。但它是一个fork,并且停止更新,所以

    pip install mysql-connector
    

    将安装这个过时的版本。

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