import pymysql
conn = pymysql.connect(
host='127.0.0.1',
user='root',
passwd='123456',
port=3306,
db='student',
charset='utf8'
)
cursor1 = conn.cursor()
sql1 = '''insert into student002 (stuid,stu_name,age,classid)
values (1002,'wang',12,9)'''
cursor1.execute(sql1)
conn.commit()
sql2 = '''select * from student002'''
cursor1.execute(sql2)
data = cursor1.fetchall()
for i in data:
print(i)
cursor1.close()
conn.close()