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