[2010-05-31]Python 2.6连接mysql

突然想起了世界上最优雅的语言python

(why 最优雅,因为强制缩进,看起来的确比较好看)

1,先装MySQLdb库,官方下载的不行,搜到这个

http://www.codegood.com/archives/4

2,遇到__init__.py什么什么的错误,

神级帖子save me http://www.phpfans.net/article/htmls/200907/MjE1MjQ5.html

找到MySQLdb文件夹的中__init__.py,注释掉from sets import ImmutableSet
class DBAPISet(ImmutableSet):添加class DBAPISet(frozenset):;找到converters.py注释掉from sets import BaseSet, Set。然后修改第45行和129行中的Set为set。

3,开始读取book数据库

import MySQLdb
conn=MySQLdb.connect(host="localhost",user="root",passwd="744411",db="book")
cursor=conn.cursor()
cursor.execute("select * from book")
res=cursor.fetchall()
print res
cursor.close()
conn.close()



[img]http://dl.iteye.com/upload/attachment/485215/4549f0f0-4ce4-30c0-a97d-3ce650c59d8f.jpg[/img]
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值