我试图从一个表中获取行,但是总是收到“none”,尽管表中有3行。
我在这个论坛上读过几次同样的问题,但没有一个解决方案对我有效,目前为止我尝试设置autocommit、显式提交、缓冲游标、unbuffered cursor、fetchall、fetchone。
Select语句在MySl workbench中运行良好,在MySql workbench中返回3行
这是我的设置:
win32上的Python 3.6.5(v3.6.5:f59c0932b4,2018年3月28日17:00:18)[MSC v.1900 64位(AMD64)]
MySql 8.0.11社区服务器-GPL Win64(x86_64)
MySql Connector for Python 3.6.5版conn = mysql.connector.connect(database='test',
user='usr',
password='pwd',
host='localhost',
port=3306)
# autocommit -> advice from web
conn.autocommit = True
print(conn.autocommit)
cursor = conn.cursor()
cursor.execute("SELECT * FROM testtable")
rows = cursor.fetchall()
# .... -> program stops here. please see output below
res