汪晓康

导航

MySQLdb操作

# 查询数据库
import MySQLdb

conn = MySQLdb.connect(
	host='localhost',
	user='root',
	passwd='root',
	db='test',
	charset='utf8'
)
c = conn.cursor()
c.execute("select * from student")
rows = c.fetchall()
for item in rows:
	print(item)

# 数据库插入
import MySQLdb

conn = MySQLdb.connect(
	host='localhost',
	user='root',
	passwd='root',
	db='test',
	charset='utf8'
)
c = conn.cursor()
c.execute("insert into student (sid,sname,sage,ssex) values('09','汪晓康','19920812','男')")
conn.commit()
rows = c.fetchall()
for item in rows:
	print(item)

posted on 2021-08-09 23:25  汪晓康  阅读(101)  评论(0编辑  收藏  举报