| mysql是一種關(guān)系型數(shù)據(jù)庫,是為了表示事物與事物之間的關(guān)系,本身存于數(shù)據(jù)庫中的內(nèi)容意義并不大,所以廣泛應(yīng)用于編程語言中,python中九含有與MySQL交互的模塊 pymysql 編程對mysql的操作 #首先需要引入pymysql模塊
import pymysql
#連接數(shù)據(jù)庫 一般需要幾個參數(shù):host  database    user    password    port    charset
my_conn = pymysql.connect(host="localhost", user="root", password="root", database="laowang", port=3306, charset="utf8")
#開啟一個事務(wù)
my_cursor = my_conn.cursor()
#執(zhí)行SQL語句(增刪改通用)
my_cursor.execute("delete from student where id = 3")
#(查詢)返回一個元組
content = my_cursor.fetchall()
print(content)
#提交
my_conn.commit()
#關(guān)閉連接
my_conn.close()
 |