1. 程式人生 > >在 Python代碼中操作mysql數據

在 Python代碼中操作mysql數據

let pre pda name mysq div pos print count

# 創建Connection連接
conn = connect(host=‘localhost‘, port=3306, user=‘root‘, password=‘mysql‘, database=‘python1‘, charset=‘utf8‘)
# 得Cursor對象
cs = conn.cursor()
# 更新
# sql = ‘update students set name="name" where id=1‘
# 刪除
# sql = ‘delete from students where id=1‘
# 執行select語句,並返回受影響的行數:查詢一條學生數據
sql = ‘select id,name from students where id = 7‘
# sql = ‘SELECT id,name FROM students WHERE id = 7‘
count=cs.execute(sql)
# 打印受影響的行數
print(count)

在 Python代碼中操作mysql數據