在树莓派中为 python 3 安装 mysql 连接器

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/38007240/
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-31 21:53:56  来源:igfitidea点击:

installing mysql connector for python 3 in raspberry pi

mysqlpython-3.xraspberry-pi2

提问by M2skills

I am new at using raspberry pi. I have a python 3.4 program that connects to a database on hostinger server. I want to install mysql connector in raspberry pi.I searched a lot but I was not able to find answers . any help would be appreciated

我是使用树莓派的新手。我有一个 python 3.4 程序,它连接到托管服务器上的数据库。我想在 raspberry pi 中安装 mysql 连接器。我搜索了很多,但找不到答案。任何帮助,将不胜感激

采纳答案by M2skills

I found no way to install mysql-connector-python that I used with windows. for python 3.4 I used the command

我发现无法安装我在 Windows 中使用的 mysql-connector-python。对于 python 3.4,我使用了命令

sudo python3 -m pip install pymysql

for python 2.7 you can use following commands

对于python 2.7,您可以使用以下命令

 sudo apt-get install python-mysqldb

or

或者

sudo apt-get install python-pip
pip install pymysql

回答by michaelemery

Before you install, it is important to run update andupgrade;

在安装之前,运行 updateupgrade很重要;

sudo apt-get update
sudo apt-get upgrade

Eitherinstall connector for Python 2;

要么Python 2安装连接器;

sudo apt-get -y install python-mysql.connector

Orinstall connector for Python 3;

或者Python 3安装连接器;

sudo apt-get -y install python3-mysql.connector

回答by Bhanu Shree R

Just use $sudo apt-get install python3-mysqldb and it works on pi-3.

只需使用 $sudo apt-get install python3-mysqldb 即可在 pi-3 上运行。