I have to deal with a large result set (could be hundreds thousands of rows, sometimes more).
They unfortunately need to be retrieved all at once (on start up).
Alternatively, you can use SSCursor
outside the connection object (it is pretty important when you already define connection and dont want all the connection use SSCursor
as a cursorclass).
import MySQLdb
from MySQLdb.cursors import SSCursor # or you can use SSDictCursor
connection = MySQLdb.connect(
host=host, port=port, user=username, passwd=password, db=database)
cursor = SSCursor(connection)
cursor.execute(query)
for row in cursor:
print(row)