MySQLdb - possible without install?

Gerhard Häring gerhard.nospam at
Thu Jul 12 15:38:48 EDT 2001

On Thu, 12 Jul 2001 10:26:22 GMT, Ken <ken_chiba at> wrote:
>I'm no expert with this at all... could I get some pointers?  I'm
>assuming that you're saying that I need to compile MySQLdb with the
>MySQL and Python versions that my provider uses.  This will result in
>the creation of a MySQLdb directory in the site-packages directory of
>Python.  Does it produce anything else?

To build MySQLdb, you might have to change some paths in, then do a
"python build". The files to install will then be in a directory named
not entirely unlike "build/lib.linux-i686-2.1". This directory is normally
copied to your site-packages dir. A simple way to use it on your provider is to
copy all of it into your cgi-bin (the py[c] files, the binary extension module
and the MySQLdb directory in it).

>After this is created, do I just copy that directory (MySQLdb) to a
>MySQLdb directory on the provider side (in this case.. within
>cgi-bin)?  And finally, what line can I put within my scripts to pull
>this information in? (ie.:  import ??)

Better look into the MySQLdb docs, but here's a simple one:

#!/usr/bin/env python
import MySQLdb
con = MySQLdb.connect( user = "me", password = "verysecret", db = "mydb",\
    host = "dbcluster" )
cursor = con.cursor()
cursor.execute( "select hello from world" )
print cursor.fetchall()

>How can this keep track of what directory MySQL and Python are in? (or
>are there configuration files that I can change - AFTER the compile?)

No need to change any files *after* you compiled it. The dynamic loader must
find the libmysqlclient library, or you'll have a problem. If this should
really happen, you can perhaps link the Python extension module statically.
You'll notice that this is the case when "import _mysql" produces something

ImportError: cannot load shared object file: No such file
or directory

Hopefully, the standard way of setting "#!/usr/bin/env python" works as first
line of your scripts. If not, you'll have to put the full path to the
interpreter there ("#!/usr/local/bin/python" or whatever ...).

mail:   gerhard <at> bigfoot <dot> de       registered Linux user #64239
web:              public key at homepage
public key fingerprint: DEC1 1D02 5743 1159 CD20  A4B6 7B22 6575 86AB 43C0
reduce(lambda x,y:x+y,map(lambda x:chr(ord(x)^42),tuple('zS^BED\nX_FOY\x0b')))

More information about the Python-list mailing list