mysql是一種關系型資料庫,是為了表示事物與事物之間的關系,本身存于資料庫中的內容意義并不大,所以廣泛應用于編程語言中,python中九含有與MySQL互動的模塊 pymysql
編程對mysql的操作
#首先需要引入pymysql模塊
import pymysql
#連接資料庫 一般需要幾個引數:host database user password port charset
my_conn = pymysql.connect(host="localhost", user="root", password="root", database="laowang", port=3306, charset="utf8")
#開啟一個事務
my_cursor = my_conn.cursor()
#執行SQL陳述句(增刪改通用)
my_cursor.execute("delete from student where id = 3")
#(查詢)回傳一個元組
content = my_cursor.fetchall()
print(content)
#提交
my_conn.commit()
#關閉連接
my_conn.close()
轉載請註明出處,本文鏈接:https://www.uj5u.com/shujuku/97510.html
標籤:MySQL
