从python访问MySQL数据库

时间:2022-09-15 16:59:06

I have been trying for the past several hours to find a working method of accessing a mysql database in python. The only thing that I've managed to get to compile and install is pyodbc but the necessary driver is not available for ppc leopard.

在过去的几个小时里,我一直在努力寻找一种在python中访问mysql数据库的工作方法。我设法编译和安装的唯一东西是pyodbc,但是必需的驱动程序不适用于ppc leopard。

I already know about this.

我已经知道了这一点。

UPDATE:
I've gotten setuptools to install, but now MySQL-python won't build.

更新:我已经安装了setuptools,但现在MySQL-python将无法构建。

UPDATE: Now I've gotten sqlalchemy to install but while it will show up when called by the command line it won't import when used in my cgi script.

更新:现在我已经安装了sqlalchemy,但是当它被命令行调用时会显示,但在我的cgi脚本中使用时它将不会导入。

3 个解决方案

#1


2  

Try SQL Alchemy.

试试SQL Alchemy。

It is awesome.

太棒了。

#2


1  

Install fink. It includes the MySQLdb package.

安装fink。它包括MySQLdb包。

#3


0  

UPDATE: Now I've gotten sqlalchemy to install but while it will show up when called by the command line it won't import when used in my cgi script.

更新:现在我已经安装了sqlalchemy,但是当它被命令行调用时会显示,但在我的cgi脚本中使用时它将不会导入。

Can you verify that the Python being invoked from your CGI script is the same as the one you get when you run Python interactively? Check which python and compare it to your webserver CGI settings. That's the only thing I can think of that would cause this - getting it installed in one Python but not the other.

您能否验证从CGI脚本调用的Python与您以交互方式运行Python时获得的Python相同?检查哪个python并将其与您的Web服务器CGI设置进行比较。这是我能想到的唯一能引起这种情况的东西 - 将它安装在一个Python而不是另一个Python中。

What OS are you on? If you're on something like Ubuntu, sudo apt-get install python-mysqldb is much more reliable than trying to build it yourself.

你在用什么操作系统?如果您使用的是Ubuntu,sudo apt-get install python-mysqldb比自己构建它更可靠。

Also, unless I'm mistaken, SQLAlchemy won't actually help you make the connection itself if you don't have a DB-API2 module (like python-mysqldb) installed - SQLAlchemy sits at the next level up, using the DB-API2 connection and making access to it more Pythonic.

另外,除非我弄错了,如果没有安装DB-API2模块(如python-mysqldb),SQLAlchemy实际上不会帮助你自己建立连接 - SQLAlchemy使用DB-位于更高层次API2连接并使其访问更多Pythonic。

#1


2  

Try SQL Alchemy.

试试SQL Alchemy。

It is awesome.

太棒了。

#2


1  

Install fink. It includes the MySQLdb package.

安装fink。它包括MySQLdb包。

#3


0  

UPDATE: Now I've gotten sqlalchemy to install but while it will show up when called by the command line it won't import when used in my cgi script.

更新:现在我已经安装了sqlalchemy,但是当它被命令行调用时会显示,但在我的cgi脚本中使用时它将不会导入。

Can you verify that the Python being invoked from your CGI script is the same as the one you get when you run Python interactively? Check which python and compare it to your webserver CGI settings. That's the only thing I can think of that would cause this - getting it installed in one Python but not the other.

您能否验证从CGI脚本调用的Python与您以交互方式运行Python时获得的Python相同?检查哪个python并将其与您的Web服务器CGI设置进行比较。这是我能想到的唯一能引起这种情况的东西 - 将它安装在一个Python而不是另一个Python中。

What OS are you on? If you're on something like Ubuntu, sudo apt-get install python-mysqldb is much more reliable than trying to build it yourself.

你在用什么操作系统?如果您使用的是Ubuntu,sudo apt-get install python-mysqldb比自己构建它更可靠。

Also, unless I'm mistaken, SQLAlchemy won't actually help you make the connection itself if you don't have a DB-API2 module (like python-mysqldb) installed - SQLAlchemy sits at the next level up, using the DB-API2 connection and making access to it more Pythonic.

另外,除非我弄错了,如果没有安装DB-API2模块(如python-mysqldb),SQLAlchemy实际上不会帮助你自己建立连接 - SQLAlchemy使用DB-位于更高层次API2连接并使其访问更多Pythonic。