python操作mysql数据库示例,增加数据库行

import pymysql
conn = pymysql.connect(host='127.0.0.1',port=3306,user='root',passwd='990310',db = 'school',charset='utf8')
cursor = conn.cursor()
l = [
    ('鸭蛋1','',2),
    ('鸭蛋2', '', 2),
    ('鸭蛋3', '', 2)
]
#r = cursor.execute('insert into student(sname,gender,class_id) values(%s,%s,%s)',(inp,'女',1))
r = cursor.executemany('insert into student(sname,gender,class_id) values(%s,%s,%s)',l)

conn.commit()
print(r)
cursor.execute('select * from class')
cursor.close()
conn.close()
posted @ 2019-12-28 10:49  Iceberg_710815  阅读(223)  评论(0编辑  收藏  举报