Для тех, кто пришел сюда с mysql
, я нашел эти ответы полезными:
используйте SSCursor
как предложено this
conn = MySQLdb.connect(host=DB_HOST, user=DB_USER, db=DB_NAME,
passwd=DB_PASSWORD, charset="utf8",
cursorclass=MySQLdb.cursors.SSCursor)
и выполнить итерацию курсора в соответствии с this
cursor = conn.cursor()
cursor.execute("select * from very_big_table;")
for row in cur:
# do what you want here
pass
Обратите внимание на то, что документ говорит You MUST retrieve the entire result set and close() the cursor before additional queries can be peformed on the connection.
, поэтому, если вы хотите написать и в то же время, вам следует использовать другое соединение, или вы получите
`_mysql_exceptions.ProgrammingError: (2014, "Commands out of sync; you can't run this command now")`