In Python 2.7.3, Wins 10, MySQL remote server 5.6.23, MySQL.connector 2.1.3,
If I wanna run these two queries together in Python MySQL.connector:
SELECT * FROM A LIMIT 5;
SELECT DISTINCT COLUM_A FROM B;
I got the following error message using the code below:
Error -1: No result set to fetch from.
Here is the code:
import mysql.connector as MySQL
cursor = conn.cursor ()
sql1 = "SELECT * FROM A LIMIT 5;SELECT DISTINCT COLUM_A FROM B"
cursor.execute(sql1,multi=True)
row = cursor.fetchall ()
warning = cursor.fetchwarnings()
print row
print warning
cursor.close ()
conn.close ()
Here is the MySQL cursor.execute() official document, which completely confuses me. Could any guru enlighten? Thanks!
解决方案
Change the code to-
iterable = cursor.execute(sql1,multi=True)
for item in iterable:
print(item.fetchall())
Should work.