title: Execute many different INSERT statements efficiently
body: <p>I am working with a system that puts failed MySQL statements into a log file along with other errors. <strong>Edit</strong>: The statements fail due to a lost connection generally. I wrote a simple python script that scans through a log file looking for INSERT statements, formats them, and creates a List of strings</p>
  
  <p>It is unlikely that any of the strings are invalid MySQL statements, but they also have no common structure (they INSERT INTO different tables, different columns, etc.). Assuming that they are all valid MySQL statements, is there a better method to execute them than this?</p>
  
  <pre><code>count = 0
  for i, statement in enumerate(insertStatements):
          if i%10000 == 0:
                  print "Completed " + str(i) + " of " + str(num) + ", " + str(float(i)/num*100.0) + "%"
  
          # An earlier step split by "INSERT INTO"
          # The MySQL statement is terminated by a '"'
          insertStatements[i] = "INSERT INTO" + statement.split('"')[0]
  
          try:
                  cursor.execute(insertStatements[i])
                  count += 1
          except mysql.connector.Error as e:
                  print e
                  print insertStatements[i] + '\n'
  
  cnx.commit()
  </code></pre>
  
  <p>It is likely that any given log will produce many MySQL statements, the one I was testing with had 4,794,454 INSERT statements</p>