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)
标签:fetchall,rows,item,MySQLdb,操作,root,conn 来源: https://www.cnblogs.com/wxkabc/p/15121228.html