黄聪:python+MySQLdb操作Mysql数据库示例代码程序教程

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

原文地址:https://www.cnblogs.com/huangcong/p/2165995.html