# 查询数据库
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)