簡體   English   中英

Python MySQL連接器無法從SELECT查詢返回所有結果

[英]Python MySQL connector fails to return all results from SELECT query

我有我使用mysql-connector-python執行的查詢。 代碼是:

try:
    conn = mycon.connect(user=****,password=****,host=****,database=****,autocommit=True)
except mycon.Error as err:
    if err.errno == errorcode.ER_ACCESS_DENIED_ERROR:
        print("Authentication error - incorrect username and/or password.")
    elif err.errno == errorcode.ER_BAD_DB_ERROR:
        print("Database does not exist.")
    else:
        print(err)
cursor = conn.cursor()
no_of_results = cursor.execute("SELECT * FROM name_table\nLIMIT 0, 1000\n")
row = cursor.fetchone()
print(row)
while row is not None:
    row = cursor.fetchone()
    print(row)
cursor.close()
conn.close()

返回:

(1, 'Mains', 'Mains electrical circuit.')
(2, 'Solar', 'Solar panels.')
(3, 'AirCon', 'Air conditioner.')
(4, 'Oven', 'Oven.')
(5, 'Power1', 'General power circuit 1.')
(6, 'Power2', 'General power circuit 2.')
(7, 'Lights1', 'Lights circuit 1.')
(8, 'Lights2', 'Lights circuit 2.')
None

但是,如果我通過My​​SQL工作台運行完全相同的查詢,則返回的結果是: MySQL Workbench結果

我不知道為什么兩個查詢返回不同的結果。 我還在下面使用Wireshark查看了網絡流量信息,但是我沒有明確的理由這樣。

MySQL工作台

Python連接器

您必須先打印該行,然后才能獲取下一行:

while row is not None:
    print(row)
    row = cursor.fetchone()

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM