This method retrieves the next row of a query result set,
returning a single sequence, or
None when no
more data is available.The returned tuple consists of data
returned by the MySQL server converted to Python objects.
The following examples show how to iterate through the result of
a query using
# Using a while-loop cursor.execute("SELECT * FROM employees") row = cursor.fetchone() while row is not None: print(row) row = cursor.fetchone() # Using the cursor as iterator cursor.execute("SELECT * FROM employees") for row in cursor: print(row)
Note that you must fetch all rows before being able to execute new queries using the same connection.