连接数据库
import pymysql
#第一种方式
db = pymysql.connect(host='localhost',user='root',password='123456',database='aaa')
#第二种方式
db = pymysql.connect('localhost','root','123456','aaa')
查询表格
#查询
curosr = db.cursor()
curosr.execute("select * from student")
result = curosr.fetchall()
for row in result:
print(row)
插入
#插入
sql = "insert into student (f_name,f_sex,f_age)values ('刘姥姥','女',65);"
curosr = db.cursor()
curosr.execute(sql)
db.commit()
删除
sql = "delete from student where f_name='刘姥姥'"
curosr = db.cursor()
curosr.execute(sql)
db.commit()
更新
sql = "update student set f_name = '刘姥姥' where f_master_id=3;"
curosr = db.cursor()
curosr.execute(sql)
db.commit()
aaa