使用pymysql进行数据库的增删改查:
import pymysql
database = pymysql.connect('127.0.0.1','root','root','jxgl',charset='utf8')
# 初始化指针
cursor = database.cursor()
# 增
# sql = "insert into students(s_no,s_name,sex,birthday,D_NO,address,phone) VALUES ('123009','zep','男','1999-07-14','D007','东山路110号','110110')"
# cursor.execute(sql)
# database.commit() # 对存储的数据修改后,需要commit
# database.close()
# 修改
# sql1 = "update students set s_name='zzzz'where s_name='zep';"
# cursor.execute(sql1)
# database.commit() # 对存储的数据修改后,需要commit
# database.close()
# 查询
# sql2 = "select s_name,sex,address from students where sex='男';"
# cursor.execute(sql2)
# result = cursor.fetchall()
# print(result)
# 删除
sql3 = "delete from students where s_name='zzzz';"
cursor.execute(sql3)
database.commit() # 对存储的数据修改后,需要commit
database.close()