[英]connect to mysql database python3.9
我在 macOS 上使用帶有 Python 3.9 版的 conda 虛擬環境。
我正在嘗試像這樣連接到 mysql 數據庫:
import MySQLdb
# Connect
db = MySQLdb.connect(
host="jgsahkjrds.amazonaws.com",
user="admin",
password="Jabc!",
)
cursor = db.cursor()
# Execute SQL select statement
cursor.execute("SELECT * from z3")
# Commit your changes if writing
# In this case, we are only reading data
# db.commit()
# Get the number of rows in the resultset
numrows = cursor.rowcount
# Get and display one row at a time
for x in range(0, numrows):
row = cursor.fetchone()
print(row[0])
# Close the connection
db.close()
運行代碼給了我這個錯誤:
ModuleNotFoundError 沒有名為“MySQLdb”的模塊
當我嘗試做pip install MySQLdb
時,我得到了這個:
找不到滿足 MySQLdb 要求的版本(來自版本:無)
錯誤:沒有為 MySQLdb 找到匹配的分布
我可以通過哪些其他方式連接到我的數據庫?
這個網站有你正在尋找的答案。 你需要 mysqlclient、mysql-connector-python 和 PyMySQL。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.