使用例子:
import MySQLdb
try:
conn = MySQLdb.connect(host='localhost',user='root',passwd='1',db='test_python')
except Exception,e:
print e
sys.exit()
cursor = conn.cursor()
sql = "create table if not exists test1(name varchar(128) primary key, age int(4))"
cursor.execute(sql)
sql = "insert into test1(name, age) values (%s, %s)"
val = (("abc", 24), ("cde", 25), ("fgh", 26))
try:
cursor.executemany(sql, val)
except Exception, e:
print e
conn.commit()