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有關
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 ‘;’ tokenmysql.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 scopemysql.cc:1622: error: expected primary-expression before ‘)’ tokenmysql.cc:1623: error: ‘rl_compentry_func_t’ was not declared in this scopemysql.cc:1623: error: expected primary-expression before ‘)’ tokenmysql.cc: In function ‘char** new_mysql_completion(const char*, int, int)’:mysql.cc:1649: error: ‘rl_completion_matches’ was not declared in this scope
$ 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
修改後的檔案
[options]# embedded: link against the embedded server library# threadsafe: use the threadsafe client# static: link against a static library (probably required for embedded)embedded = Falsethreadsafe = Falsestatic = 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 = /usr/local/bin/mysql_config# 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,:) 測試下
$ pythonPython 2.6.5 (r265:79063, Jun 12 2010, 17:07:01)[GCC 4.3.4 20090804 (release) 1] on cygwinType "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 /cygdrive/d/MySQL-python-1.2.3 is being added to sys.path
好像是有衝突了,ls一把,還是看不明白
/cygdrive/d/MySQL-python-1.2.3$ lsHISTORY README dist setup.cfg setup_posix.pyc testsMANIFEST.in _mysql.c doc setup.py setup_windows.pyMySQL_python.egg-info _mysql_exceptions.py ez_setup.py setup_common.py setuptools-0.6c11.tar.gzMySQLdb _mysql_exceptions.pyc metadata.cfg setup_common.pyc site.cfgPKG-INFO build pymemcompat.h setup_posix.py site.cfg.bak
百度下,install後MySQLdb模組已經被放到python的site-packages目錄中;但在目前的目錄也存在相同的模組,所以可能會重複匯入。換個目錄再試試
$ pythonPython 2.6.5 (r265:79063, Jun 12 2010, 17:07:01)[GCC 4.3.4 20090804 (release) 1] on cygwinType "help", "copyright", "credits" or "license" for more information.>>> import MySQLdb>>>
大功告成,不再提示錯誤資訊了。
3 連下mysql - server瞅瞅,mysql_test.py
import MySQLdbtry: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()
sku : 2147483647 0sku : 2147483647 0sku : 2147483647 0sku : 2147483647 0sku : 2147483647 0
參考:http://suddymail.org/show-171-1.html
http://awwsheezy.com/2011/05/03/dbdmysql-dbi-perl-mysql-and-cygwin-together-at-last/
http://hi.baidu.com/seaweaver/item/1db27a152cefb125f7625cf6