zoukankan      html  css  js  c++  java
  • python26 调用mysql 5.1

    备份1:一个专搞python mysql链接的人的博客 http://hi.baidu.com/jackbillow/blog/item/ae29e36ecaea96dd80cb4a56.html

    资料下载地址https://files.cnblogs.com/finallyliuyu/pythonmysql.rar

    建议大家先将资料中的两个dll文件拷贝到c:\windows\system32下面,然后直接 MySQL-python-1.2.2.win32-py2.6.exe 如果报错再按下面修改

    稀里糊涂搞了一晚上,还是有bug,今天在重装莫名其妙地好了

    下面安装方法共享一下(声明 来源于网上找了很多资料就这个可以使用)

    python2.6连接mysql数据库的问题(http://hi.baidu.com/maml897/blog/item/94d9182bed0e85325343c183.html)
    2009-11-06 10:40

    我是在windows下面测试的:

    首先要安装MySQL-python-1.2.2.win32-py2.6.exe,如果在linux下则安装linux下面的对应文件,可以再网上下载。

    接下来让我们写一段测试代码看看是不是已经可以正确连接了:

    1
    2
    3
    4
    5
    6
    7
    import MySQLdb
    db = MySQLdb.connect(user='me', db='mydb', passwd='secret', host='localhost')
    cursor = db.cursor()
    cursor.execute('SELECT name FROM books ORDER BY name')
    names = [row[0] for row in cursor.fetchall()]
    print names
    db.close()

    如果在import MySQLdb的时候出现下面的提示错误:

    1
    2
    3
    4
    'deprecation warning': 
    C:\Python\lib\site-packages\MySQLdb\__init__.py:34: 
    DeprecationWarning: the sets module is deprecated 
    from sets import ImmutableSet

    那我们试着改写类库文件:

    1) 打开 “__init__”, 替换:
    from sets import ImmutableSet
    class DBAPISet(ImmutableSet):
    改为
    class DBAPISet(frozenset)

    2) 打开”converters.py”, 删除:
    from sets import BaseSet, Set

    3) 在”converters.py” 文件中把 “Set” 替换成 “set” (IMPORTANT: 有两处需要修改):
    line 48: return set([ i for i in s.split(',') if i ])
    line 128: set: Set2Str

  • 相关阅读:
    NoSQL数据库 continue posting...
    CAP 理论
    Clojure Web 开发 (一)
    HttpClient 4.0.x Tips
    zZ Java中String和Byte[]之间的那些事
    使用nhibernate出现Could not find the dialect in the configuration
    eclipse导入项目出现Project has no default.properties file! Edit the project properties to set one.
    今天开通此博~
    美国白蛾入侵北京 GIS兵法破解危局
    HTML5 存取Json
  • 原文地址:https://www.cnblogs.com/finallyliuyu/p/1712550.html
Copyright © 2011-2022 走看看