`
crispgm
  • 浏览: 24399 次
  • 性别: Icon_minigender_1
  • 来自: 深圳
最近访客 更多访客>>
文章分类
社区版块
存档分类
最新评论

[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()




  • 大小: 106.9 KB
分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics