import pymysql
my = pymysql.connect(
host="127.0.0.1",
user="root",
password="123456789",
db="world"
)
cur = my.cursor()
cur.execute("DROP TABLE IF EXISTS minyan;")
sql = '''create table minyan(sid char(10) primary key not null,sname char(5),sxb char(1));'''
cur.execute(sql)
sql = '''INSERT INTO world.minyan (sid, sname, sxb) VALUES ('230303048', 'my', 'n'),('230303050', 'yzh', 'n');'''
cur.execute(sql)
sql = "SELECT * FROM minyan;"
cur.execute(sql)
date = cur.fetchall()
for i in date:
print(i)
sql = '''update minyan set sname='lfc' where sid=%s'''
cur.execute(sql, ("230303050",))
my.commit()
print("-------------------------------------")
sql = "SELECT * FROM minyan;"
cur.execute(sql)
date = cur.fetchall()
for i in date:
print(i)
sql = "delete from minyan where sname=%s"
cur.execute(sql, ("lfc",))
print("-------------------------------------")
sql = "SELECT * FROM minyan;"
cur.execute(sql)
date = cur.fetchall()
for i in date:
print(i)
my.commit()
cur.close()
my.close()
© 版权声明
THE END
暂无评论内容