python练习005--数据库处理

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()
posted @ 2021-03-17 13:20  沈一愣  阅读(48)  评论(0编辑  收藏  举报