python之mysql连接 MySQLdb
http://www.yqxbc.com  发布时间:2015-03-16 09:14 来源:未知 浏览:加载中

1、根据操作系统下载MySQL-python   http://www.codegood.com/archives/4,也可以在https://sourceforge.net/projects/mysql-python/files/mysql-python/得到linux下版本,我这里用到的win32和python2.6

2、双击安装MySQLdb

3、然后import MySQLdb。出现File "C:/Python26/lib/site-packages/MySQLdb/__init__.py", line 19, in <module> 
ImportError: DLL load failed: 找不到指定的模块。是缺少2个dll文件分别为 libguide40.dll和libmmd.dll。下载之,然后复制到 WINDOWS/system32 或者Python26/Lib/site-packages下

4、然后import MySQLdb。再出现sys:1: DeprecationWarning: the sets module is deprecated 的错误,再次搜索,原因是2.6不知sets这个模块,不过已经添加了set内置函数。找到MySQLdb文件夹的中__init__.py,注释掉from sets import ImmutableSet
class DBAPISet(ImmutableSet):添加class DBAPISet(frozenset):;找到converters.py注释掉from sets import BaseSet, Set。然后修改第45行和129行中的Set为set。

5、import MySQLdb
     conn=MySQLdb.connect(host="localhost",user="root",passwd="root",db="test")

连接成功mysql使用api :http://mysql-python.sourceforge.net/MySQLdb.html

如果你有好的win10资讯或者win10教程,以及win10相关的问题想要获得win10系统下载的关注与报道。
欢迎加入发送邮件到657025171#qq.com(#替换为@)。期待你的好消息!