title: Generate an SQL statement to insert multiple lines into a MySQL database at once using Python
body: <p>I am trying to generate a variable that I could use to insert multiple lines into a MySQL database or save to a file.</p>
  
  <p>As I am new to python my mind is now buzzing with all the new concepts I am having to learn and I'm looking for a little reassurance that my approach is a good one.</p>
  
  <p>The SQL syntax for inserting multiple items into a table is this:</p>
  
  <pre><code>INSERT INTO 'tablename' ('column1', 'column2') VALUES
    ('data1', 'data2'),
    ('data3', 'data4'),
    ('data5', 'data6'),
    ('data7', 'data8');
  </code></pre>
  
  <p>This is the code I have:</p>
  
  <pre><code>import shelve
  
  shelf = shelve.open('test.db', flag='r')
  
  sql = "INSERT INTO 'myTableName' ( "
  sql += ", ".join(shelf.itervalues().next())
  sql = " ) VALUES "
  for s in shelf: 
  
    sql += "( "
    sql += ', '.join(['\'%s\'' % ( value ) for (key, value) in shelf[s].items()])
    sql += " ),"
  
  shelf.close()
  
  print sql
  </code></pre>
  
  <p>It so nearly works (it has a trailing , instead of a ; on the final sql addition) but I'm sure there must be a more concise approach.  Can you tell me what it is?</p>