On the off chance that you are utilizing the default cursor, a MySQLdb.cursors.Cursor, the whole outcome set will be put away on the customer side (for example in a Python list) when the cursor.execute() is finished.
Even if you utilize,
for row in cursor:
you won't get any decrease in memory impression. The whole outcome set has effectively been put away in a list (See self._rows in MySQLdb/cursors.py).
In case, if you utilize SSCursor or SSDictCursor:
import MySQLdb
import MySQLdb.cursors as cursors
conn = MySQLdb.connect(..., cursorclass=cursors.SSCursor)
Then, the result set will be stored in the mysqld (Server). Now, You can compose
cursor = conn.cursor()
cursor.execute('SELECT * FROM HUGETABLE')
for row in cursor:
print(row)
also, the rows will be brought individually from the server, in this way not expecting Python to construct a tremendous list of tuples first, and hence saving money on memory.
Something else, as others have effectively expressed, cursor.fetchall() and list(cursor) are basically something very similar.
Wanna become a Python expert? Come and join the python certification course and get certified.