[转帖]cygwin安装python-mysql _VMware, Unix及操作系统讨论区_Weblogic技术|Tuxedo技术|中间件技术|Oracle论坛|JAVA论坛|Linux/Unix技术|hadoop论坛_联动北方技术论坛  
网站首页 | 关于我们 | 服务中心 | 经验交流 | 公司荣誉 | 成功案例 | 合作伙伴 | 联系我们 |
联动北方-国内领先的云技术服务提供商
»  游客             当前位置:  论坛首页 »  自由讨论区 »  VMware, Unix及操作系统讨论区 »
总帖数
1
每页帖数
101/1页1
返回列表
0
发起投票  发起投票 发新帖子
查看: 2114 | 回复: 0   主题: [转帖]cygwin安装python-mysql         下一篇 
    本主题由 koei123 于 2015-2-6 4:58:23 移动
gang
注册用户
等级:上等兵
经验:142
发帖:79
精华:0
注册:2011-12-30
状态:离线
发送短消息息给gang 加好友    发送短消息息给gang 发消息
发表于: IP:您无权察看 2015-1-8 16:04:22 | [全部帖] [楼主帖] 楼主

1 安装 mysql-5.0.56.tar.gz

下载地址  http://down.51cto.com/data/320800

$ tar -zxvf mysql-5.0.56.tar.gz
$ cd mysql-5.0.56
$ ./configure --without-server
$ ./make


一堆异常,和readline有关

[plain] view plaincopy
<span style="font-size:12px;">mysql.cc:315: error: redefinition of ‘struct _hist_entry’
../include/readline/readline.h:53: error: previous definition of ‘struct _hist_entry’
mysql.cc:318: error: invalid type in declaration before ‘;’ token
mysql.cc:318: error: conflicting declaration ‘typedef int HIST_ENTRY’
../include/readline/readline.h:56: error: ‘HIST_ENTRY’ has a previous declaration as ‘typedef struct _hist_entry HIST_ENTRY’
mysql.cc: In function ‘void initialize_readline(char*)’:
mysql.cc:1622: error: ‘rl_completion_func_t’ was not declared in this scope
mysql.cc:1622: error: expected primary-expression before ‘)’ token
mysql.cc:1623: error: ‘rl_compentry_func_t’ was not declared in this scope
mysql.cc:1623: error: expected primary-expression before ‘)’ token
mysql.cc: In function ‘char** new_mysql_completion(const char*, int, int)’:
mysql.cc:1649: error: ‘rl_completion_matches’ was not declared in this scope</span>
$ make clean   #重要,鼓捣了好几次,运行clean后才成功
$ ./configure --without-server --without-readline
$ make


再没见到error字样,输入

$ mysql
ERROR 2002 (HY000): Can't connect to local MySQL server through socket '/tmp/mysql.sock' (2)


没提示找不到mysql,应该是安装成功了

2 安装mysql-python setuptools

wget http://sourceforge.net/projects/mysql-python/files/mysql-python/1.2.3/MySQL-python-1.2.3.tar.gz/download
$ tar -zxvf MySQL-python-1.2.3.tar.gz
$ cd MySQL-python-1.2.3
$ python setup.py build
Traceback (most recent call last):
File "setup.py", line 5, in <module>
from setuptools import setup, Extension
ImportError: No module named setuptools


提示没有setuptools,“setuptools是 Python Enterprise Application Kit(PEAK)的一个副项目,它 是一组Python的 distutilsde工具的增强工具(适用于 Python 2.3.5 以上的版本,64 位平台则适用于 Python 2.4 以上的版本),可以让程序员更方便的创建和发布 Python 包,特别是那些对其它包具有依赖性的状况。”--百度百科

安装setuptools,很顺利。参考baidu的一个帖子~

$ wget http://pypi.python.org/packages/source/s/setuptools/setuptools-0.6c11.tar.gz
$ tar zxvf setuptools-0.6c11.tar.gz
$ cd setuptools-0.6c11
$ python setup.py build
$ python setup.py install


接着安装python-mysql,修改site.cfg文件

$ cd MySQL-python-1.2.3
$ whereis mysql
mysql: /usr/local/bin/mysql.exe /usr/local/lib/mysql
$ whereis mysql_config
mysql_config: /usr/local/bin/mysql_config /opt/mysql/bin/mysql_config


修改后的文件

[plain] view plaincopy
[options]
# embedded: link against the embedded server library
# threadsafe: use the threadsafe client
# static: link against a static library (probably required for embedded)
embedded = False
threadsafe = False
static = True
# The path to mysql_config.
# Only use this if mysql_config is not on your PATH, or you have some weird
# setup that requires it.
mysql_config = <span style="color:#ff0000;">/usr/local/bin/mysql_config</span>
# The Windows registry key for MySQL.
# This has to be set for Windows builds to work.
# Only change this if you have a different version.
# registry_key = SOFTWARE\MySQL AB\MySQL Server 5.0


(a)放开mysql_config项,内容是whereis mysql_config检索结果,后面的/opt/mysql/bin/mysql_config没有测试过,估计也好使~

(b)关闭registry_key注册表项

(c)最上面的3个True,False选项参考其他帖子的。

$ python setup.py build
$ python setup.py install


没见着安装成功的提示信息,不过没显示error,:) 测试下

[python] view plaincopy
<span style="color:#464646;">$ python
Python 2.6.5 (r265:79063, Jun 12 2010, 17:07:01)
[GCC 4.3.4 20090804 (release) 1] on cygwin
Type "help", "copyright", "credits" or "license" for more information.
>>> import MySQLdb
/usr/lib/python2.6/site-packages/MySQL_python-1.2.3-py2.6-cygwin-1.7.9-i686.egg/_mysql.py:3: UserWarning: Module _mysql was already imported from /usr
/lib/python2.6/site-packages/MySQL_python-1.2.3-py2.6-cygwin-1.7.9-i686.egg/_mysql.pyc, but </span><span style="color:#ff0000;">/cygdrive/d/MySQL-python-1.2.3 is being added to sys.path</span>


好像是有冲突了,ls一把,还是看不明白

[plain] view plaincopy
/cygdrive/d/MySQL-python-1.2.3
$ ls
HISTORY                README                 dist           setup.cfg         setup_posix.pyc           tests
MANIFEST.in            _mysql.c               doc            setup.py          setup_windows.py
MySQL_python.egg-info  _mysql_exceptions.py   ez_setup.py    setup_common.py   setuptools-0.6c11.tar.gz
MySQLdb                _mysql_exceptions.pyc  metadata.cfg   setup_common.pyc  site.cfg
PKG-INFO               build                  pymemcompat.h  setup_posix.py    site.cfg.bak


百度下,install后MySQLdb模块已经被放到python的site-packages目录中;但在当前目录也存在相同的模块,所以可能会重复导入。换个目录再试试

[python] view plaincopy
$ python
Python 2.6.5 (r265:79063, Jun 12 2010, 17:07:01)
[GCC 4.3.4 20090804 (release) 1] on cygwin
Type "help", "copyright", "credits" or "license" for more information.
>>> import MySQLdb
>>>


大功告成,不再提示错误信息了。

3 连下mysql - server瞅瞅,mysql_test.py

[python] view plaincopy
import MySQLdb
try:
connection = MySQLdb.connect(user="***",passwd="***",host="*.*.*.*",db="test")
except:
print "Could not connect to MySQL server."
exit( 0 )
cursor = connection.cursor()
cursor.execute("SELECT parent_id,sku_id FROM datong where sku_id = 0")
print "Rows selected:", cursor.rowcount
for row in cursor.fetchall():
print "sku : ", row[0], row[1]
cursor.close()
[plain] view plaincopy
sku :  2147483647 0
sku :  2147483647 0
sku :  2147483647 0
sku :  2147483647 0
sku :  2147483647 0


--转自 北京联动北方科技有限公司

该贴由koei123转至本版2015-2-6 4:58:23



赞(0)    操作        顶端 
总帖数
1
每页帖数
101/1页1
返回列表
发新帖子
请输入验证码: 点击刷新验证码
您需要登录后才可以回帖 登录 | 注册
技术讨论