简体   繁体   English

在python中导入MySQLdb时出错

[英]error to import MySQLdb in python

I have error to connect existing mysql database in python and i unable to do 我在连接python中的现有mysql数据库时出错并且无法执行

pip install mysql command

import MySQLdb
db = MySQLdb.connect(host='10.10', port=3306, user='system', passwd='xyz' db='Reporting')
print(db)

I want to retrieve the data from mysql database in python. 我想从python中的mysql数据库中检索数据。

使用pip install MySQL-python代替

You need to install the dependencies before installation with pip . 您需要先安装依赖项,然后才能使用pip进行安装。

apt-get install python-dev libmysqlclient-dev

And than, the installation with pip like the answer of Zart should work. 而且,比起Zart的答案,使用pip进行安装应该可以工作。

pip install MySQL-python

The above answer is only for Linux System. 上面的答案仅适用于Linux系统。

For Windows you can download the .whl file from here mysqlclient and install it. 对于Windows,您可以从mysqlclient下载.whl文件并安装。 Please download the right version. 请下载正确的版本。 win32 for 32 bit. win32的32位。 amd64 for 64 bit. 64位的amd64 cp27 for python 2.7, cp34 for python 3.4, cp35 for python 3.5 cp27于python 2.7的cp34cp34于python 3.4的cp35cp35于python 3.5的cp35

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM