2012-02-13 145 views
0

我在http://www.mysql.com/downloads/connector/c/找到了mysqllib。如何在沒有安裝MySQL服務器的情況下安裝Python MySQLdb

那麼我可以在不安裝MySQL服務器的情況下安裝MySQLdb嗎?

只需將mysqlib複製到/usr/local/mysql

難道有可能嗎?以及如何做到這一點?

哪個版本會匹配我的機器(我使用OSX Lion)?

我想用它連接到Django的另一臺機器上的MySQL服務器。

感謝您的幫助!

================================

件事,我曾嘗試已經

  1. 下載http://www.mysql.com/downloads/connector/c/ 64位

  2. 提取到/ usr /本地/ MySQL的

  3. 下載的MySQL的Python-1.2.3

  4. 創建符號鏈接的gcc-4.2至GCC(因爲當它編譯運行gcc-4.2而不是gcc)

  5. 在MySQL的Python-1.2.3文件夾編輯setup_posix.py

    編輯mysql_config.path =「/ USR /本地/ MySQL的/斌/ mysql_config」

  6. sudo的蟒蛇setup.py乾淨

  7. 編輯_mysql.c每一個包括mysqllib到正確的路徑

例如#包括 「的mysql.h」 ===>的#include 「/usr/local/mysql/include/mysql.h」

  1. sudo的蟒蛇的setup.py建立

,我發現這個錯誤

Oats-MacBook:MySQL-python-1.2.3 Oat$ sudo python setup.py build 
running build 
running build_py 
creating build 
creating build/lib.macosx-10.6-intel-2.7 
copying _mysql_exceptions.py -> build/lib.macosx-10.6-intel-2.7 
creating build/lib.macosx-10.6-intel-2.7/MySQLdb 
copying MySQLdb/__init__.py -> build/lib.macosx-10.6-intel-2.7/MySQLdb 
copying MySQLdb/converters.py -> build/lib.macosx-10.6-intel-2.7/MySQLdb 
copying MySQLdb/connections.py -> build/lib.macosx-10.6-intel-2.7/MySQLdb 
copying MySQLdb/cursors.py -> build/lib.macosx-10.6-intel-2.7/MySQLdb 
copying MySQLdb/release.py -> build/lib.macosx-10.6-intel-2.7/MySQLdb 
copying MySQLdb/times.py -> build/lib.macosx-10.6-intel-2.7/MySQLdb 
creating build/lib.macosx-10.6-intel-2.7/MySQLdb/constants 
copying MySQLdb/constants/__init__.py -> build/lib.macosx-10.6-intel-2.7/MySQLdb/constants 
copying MySQLdb/constants/CR.py -> build/lib.macosx-10.6-intel-2.7/MySQLdb/constants 
copying MySQLdb/constants/FIELD_TYPE.py -> build/lib.macosx-10.6-intel-2.7/MySQLdb/constants 
copying MySQLdb/constants/ER.py -> build/lib.macosx-10.6-intel-2.7/MySQLdb/constants 
copying MySQLdb/constants/FLAG.py -> build/lib.macosx-10.6-intel-2.7/MySQLdb/constants 
copying MySQLdb/constants/REFRESH.py -> build/lib.macosx-10.6-intel-2.7/MySQLdb/constants 
copying MySQLdb/constants/CLIENT.py -> build/lib.macosx-10.6-intel-2.7/MySQLdb/constants 
running build_ext 
building '_mysql' extension 
creating build/temp.macosx-10.6-intel-2.7 
gcc-4.2 -fno-strict-aliasing -fno-common -dynamic -isysroot /Developer/SDKs/MacOSX10.6.sdk -arch i386 -arch x86_64 -g -O2 -DNDEBUG -g -O3 -Dversion_info=(1,2,3,'final',0) -D__version__=1.2.3 -I/usr/local/include -I/Library/Frameworks/Python.framework/Versions/2.7/include/python2.7 -c _mysql.c -o build/temp.macosx-10.6-intel-2.7/_mysql.o 
In file included from _mysql.c:36: 
/usr/local/mysql/include/my_config.h:185:1: warning: "SIZEOF_LONG" redefined 
In file included from /Library/Frameworks/Python.framework/Versions/2.7/include/python2.7/Python.h:9, 
       from pymemcompat.h:10, 
       from _mysql.c:29: 
/Library/Frameworks/Python.framework/Versions/2.7/include/python2.7/pymacconfig.h:54:1: warning: this is the location of the previous definition 
In file included from _mysql.c:36: 
/usr/local/mysql/include/my_config.h:205:1: warning: "SIZEOF_SIZE_T" redefined 
In file included from /Library/Frameworks/Python.framework/Versions/2.7/include/python2.7/Python.h:9, 
       from pymemcompat.h:10, 
       from _mysql.c:29: 
/Library/Frameworks/Python.framework/Versions/2.7/include/python2.7/pymacconfig.h:56:1: warning: this is the location of the previous definition 
gcc-4.2 -bundle -undefined dynamic_lookup -arch i386 -arch x86_64 -isysroot /Developer/SDKs/MacOSX10.6.sdk -isysroot /Developer/SDKs/MacOSX10.6.sdk -g build/temp.macosx-10.6-intel-2.7/_mysql.o -L/usr/local/lib -lmysql -lpthread -o build/lib.macosx-10.6-intel-2.7/_mysql.so 
ld: warning: directory not found for option '-L/usr/local/lib' 
ld: library not found for -lmysql 
collect2: ld returned 1 exit status 
ld: warning: directory not found for option '-L/usr/local/lib' 
ld: library not found for -lmysql 
collect2: ld returned 1 exit status 
lipo: can't open input file: /var/tmp//ccnEbgua.out (No such file or directory) 
error: command 'gcc-4.2' failed with exit status 1 

回答

2

您可能想嘗試PyMySQL - 這是MySql客戶端的python實現。所以你不需要擺弄二進制文件和管理員權限。

0

你想連接到另一臺機器上的MySQL服務器嗎?如果是這樣,那麼最簡單的事情就是安裝你的(我推測)Linux發行版附帶的libmysql軟件包。

如果你說的是MySQL的嵌入式版本(沒有服務器的任何地方),那麼你需要下載mysql-python的源代碼,修改site.cfg來指定支持嵌入式而不是服務器並重建它。

+2

我使用OSX Lion 我想連接到另一臺機器上的MySQL服務器 – Geno 2012-02-13 17:32:16

相關問題