标签:mysql
#!/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()
#对数据进行操作
sql = "update user set name=%s where id=7" #定义sql语句,用于修改ID为7的name字段
params = ("zhongjw",) #修改为"zhongjw"
cur.execute(sql,params)
conn.commit() #提交请求
#关闭数据库连接
cur.close()
conn.close()本文出自 “FA&IT运维-Q群:223843163” 博客,请务必保留此出处http://freshair.blog.51cto.com/8272891/1876237
标签:mysql
原文地址:http://freshair.blog.51cto.com/8272891/1876237