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()