title: Updating millions of rows in MySQL -- when to commit
body: <p>I have a for loop that goes through millions of objects. What would be the suggested way to commit this? Here are a few examples I was thinking of:</p>
  
  <pre><code># after each
  for item in items:
      cursor.execute()
      conn.commit()
  
  # at the end
  for item in items:
      cursor.execute()
  conn.commit()
  
  # after N items
  for n, item in enumerate(items):
      cursor.execute()
      if n % N == 0:
          conn.commit()
  conn.commit()
  </code></pre>
  
  <p>Which of the above would be the most efficient?</p>