#!/usr/bin/env python # -*- coding: utf-8 -*- import MySQLdb #建立連接 conn = MySQLdb.connect(host='127.0.0.1',user='root',passwd='1qaz#EDC',db='test_db') cur = conn.cursor() #對(duì)數(shù)據(jù)進(jìn)行操作 sql = "update user set name=%s where id=7" #定義sql語句,用于修改ID為7的name字段 params = ("zhongjw",) #修改為"zhongjw" cur.execute(sql,params) conn.commit() #提交請(qǐng)求 #關(guān)閉數(shù)據(jù)庫連接 cur.close() conn.close()