Python對MySql數據庫進行增刪改查

該部分的內容需要有一定基礎,如果需要了解基礎的話,點擊鏈接------>Python操作Mysql數據庫步驟以及常用方法

1、增加數據

  • 關鍵字:insert into
sql = ”insert into news(title,content) values('今天發生了一件大事','狗丟了')“
result = link.execute(sql)
db.commit()

2、修改數據

  • 關鍵字:update
sql = “update news set content='狗找到了' where id=1”
result = link.execute(sql)
db.commit()

3、查看數據

  • 關鍵字:select
sql = "select * from student"
result = link.execute(sql)
data =link.fetchall()
print(data)

4、刪除數據

  • 關鍵字:delete
sql = "ddelete from studnet news where id=1"
result = link.execute(sql)

print(result)
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章