gpt4 book ai didi

Python MySQLdb 连接导入错误

转载 作者:行者123 更新时间:2023-11-29 11:41:55 25 4
gpt4 key购买 nike

我尝试使用以下代码连接数据库:

import MySQLdb

db = MySQLdb.connect(host="localhost", # your host, usually localhost
user="root", # your username
passwd="root", # your password
db="test101") # name of the data base

# you must create a Cursor object. It will let
# you execute all the queries you need
cur = db.cursor()

# Use all the SQL you like
cur.execute("SELECT * FROM test1")

# print all the first cell of all the rows
for row in cur.fetchall():
print row[0]

db.close()

但是,我在控制台上收到以下错误消息:

Traceback (most recent call last):
File "C:\Users\JRambo\workspace\DBConnection\src\DBConnection.py", line 6, in <module>
import MySQLdb
File "C:\Python27\lib\site-packages\MySQLdb\__init__.py", line 19, in <module>
import _mysql
ImportError: DLL load failed: %1 is not a valid Win32 application.

我严格按照步骤进行。 How do I connect to a MySQL Database in Python?

最佳答案

您可能想要验证您是否拥有正确的 Python 位和正确的 MySQLdb 位。如果您有 32 位 Python 和 64 位 MySQLdb,它将无法工作。我遇到了类似的问题,具有相同的回溯错误,当我安装了每个应用程序的正确位类型时,宾果!希望这有帮助!

关于Python MySQLdb 连接导入错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35639703/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com