import MySQLdb
#创建链接
conn=MySQLdb.Connect(host='localhost',user='root',passwd='',db="xingming")
#生成游标
cursor=conn.cursor()
#插入多条记录
cursor.executemany(
"""INSERT INTO xm (x, m)
VALUES (%s, %s)""",
[
("h","c"),
("g","y")
] )
#查询
count=cursor.execute('select * from xm')
results = cursor.fetchall()
for r in results:
print r
本文转自黄聪博客园博客,原文链接:http://www.cnblogs.com/huangcong/archive/2011/09/04/2165995.html,如需转载请自行联系原作者