MySQLdb Executemany error
<p>I'm having issues with executemany returning the following error</p>

<pre><code>(1064, "You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'IBM'',''1998-01-02 09:30:00'',''104.5'',''104.5'',''104.5'',''104.5'',''67000'')' at line 2")
</code></pre>

<p>Whats interesting is I'm using the EXACT same syntax successfully with just plain execute command. To demonstrate, this code will successfully add a record using execute, however using the SAME syntax with execute many is returning the above error. Any insight?</p>

<pre><code>import MySQLdb
from MySQLdb import *
import datetime



db1 = MySQLdb.connect(host="127.0.0.1",user="root",passwd="password")
c = db1.cursor()
c.execute("use securities_master")


testdata = [('IBM', datetime.datetime(1998, 1, 2, 9, 30), '104.5', '104.5', '104.5', '104.5', '67000'),
    ('IBM', datetime.datetime(1998, 1, 2, 9, 31), '104.375', '104.5', '104.375', '104.375', '10800'),
    ('IBM', datetime.datetime(1998, 1, 2, 9, 32), '104.4375', '104.5', '104.375', '104.5', '13300'),
    ('IBM', datetime.datetime(1998, 1, 2, 9, 33), '104.4375', '104.5', '104.375', '104.375', '16800'),
    ('IBM', datetime.datetime(1998, 1, 2, 9, 34), '104.375', '104.5', '104.375', '104.375', '4801'),
    ('IBM', datetime.datetime(1998, 1, 2, 9, 35), '104.4375', '104.5', '104.375', '104.375', '23300'),
    ('IBM', datetime.datetime(1998, 1, 2, 9, 36), '104.4375', '104.4375', '104.375', '104.4375', '2600'),
    ('IBM', datetime.datetime(1998, 1, 2, 9, 37), '104.375', '104.375', '104.375', '104.375', '2800'),
    ('IBM', datetime.datetime(1998, 1, 2, 9, 38), '104.375', '104.4375', '104.375', '104.4375', '11101')]

sql = """INSERT IGNORE INTO stocks_datamine (symbol_id,price_date,open_price,high_price,low_price,close_price,volume) VALUES('%s','%s','%s','%s','%s','%s','%s')"""

for record in testdata[:1]:#test insert on one record
    sql_statement = sql%record
    c.execute(sql_statement)
    db1.commit()
    print 'success!'

#same sql statement just for multiple records - returns error :(


c.executemany(sql, testdata)
db1.commit()
</code></pre>

<p>The problem is in <code>sql</code> query, you added quotes to <code>%s</code> (remove them):  </p>

<pre><code>sql = """INSERT ... VALUES(%s, %s, %s, %s, %s, %s, %s)
</code></pre>

python mysql-python