如何在不安装 MySQL Server 的情况下安装 Python MySQLdb

发布于 2025-01-05 01:07:12 字数 4503 浏览 4 评论 0原文

我在 http://www.mysql.com/downloads/connector/c/。

那么我可以在不安装MySQL Server的情况下安装MySQLdb吗?

只需将 mysqlib 复制到 /usr/local/mysql 即可?

这可能吗?以及如何做到这一点?

哪个版本适合我的机器(我使用 OSX Lion)?

我想用它来连接到另一台机器上的 Django MySQL 服务器。

感谢您的帮助!

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

我已经尝试过的事情

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

  2. 解压到/usr/local/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/local/mysql/bin/mysql_config"

  6. sudo python setup.py clean

  7. 编辑 _mysql.c 每个包含 mysqllib 到正确的路径< /p>

示例 #include "mysql.h" ===> #include "/usr/local/mysql/include/mysql.h"

  1. sudo python setup.py build

我发现了这个错误

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

I found mysqllib at http://www.mysql.com/downloads/connector/c/.

So can I install MySQLdb without installing MySQL Server?

Just copy mysqlib to /usr/local/mysql?

Could it be possible? And how to do that?

And which version will match my machine (I use OSX Lion)?

I want to use it to connect to a MySQL server on another machine for Django.

Thanks for help!

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

Thing that I had try already

  1. download http://www.mysql.com/downloads/connector/c/ 64-bit

  2. extract to /usr/local/mysql

  3. download MySQL-python-1.2.3

  4. create symbolic link gcc-4.2 to gcc (because when it compile it run gcc-4.2 instead of gcc)

  5. in MySQL-python-1.2.3 folder edit setup_posix.py
    edit mysql_config.path = "/usr/local/mysql/bin/mysql_config"

  6. sudo python setup.py clean

  7. edit _mysql.c every include mysqllib to proper path

example #include "mysql.h" ===> #include "/usr/local/mysql/include/mysql.h"

  1. sudo python setup.py build

and I found this error

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

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

榕城若虚 2025-01-12 01:07:12

你可能想尝试 PyMySQL - 它是 MySql 客户端的 python 实现。因此,您无需摆弄二进制文件和管理权限。

You might want try PyMySQL - it's a python implementation of MySql client. So you will not need to fiddle with binaries and admin rights.

睫毛溺水了 2025-01-12 01:07:12

您想连接到另一台机器上的 MySQL 服务器吗?如果是这样,那么最简单的事情就是安装你的(我认为)Linux 发行版附带的 libmysql 软件包。

然而,如果您谈论的是 MySQL 的嵌入式版本(任何地方都没有服务器),那么您需要下载 mysql-python 的源代码,修改 site.cfg 以指定对嵌入式而不是服务器的支持并重建它。

Do you want to connect to a MySQL Server on another machine? If so then the easiest thing would be to install the libmysql package that comes with your (I presume) Linux distribution.

If however you're talking about the embedded version of MySQL (without a server anywhere) then you need to download the source for mysql-python, modify site.cfg to specify support for embedded rather than server and rebuild it.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文