您的位置:首页 > 编程语言 > Python开发

python MySQLdb简单操作

2015-08-28 16:10 609 查看
#!usr/bin/env python
#coding:utf-8
import MySQLdb
# 打开数据库连接
db = MySQLdb.connect("localhost","root","db","table" )
# 使用cursor()方法获取操作游标
cursor = db.cursor()
# 使用execute方法执行SQL语句
cursor.execute("select * from table")
# 使用 fetchone() 方法获取一条数据库。
data = cursor.fetchone()
data=cursor.fetchall()
for row in data:
print row[0]

#提交数据库操作
db.commit()
# 关闭数据库连接
db.close()
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: