Accessing MySQL *without* using MySQLdb

Skip Montanaro skip at pobox.com
Tue Oct 1 01:37:26 EDT 2002


    Luis> I'm writing a few Python scripts for CGI. My hosting company sort
    Luis> of supports Python (it has Python 1.5.2 running in the server -
    Luis> Red Hat Linux + Apache) and MySQL. However, they are not very keen
    Luis> in installing new modules (e.g. MySQLdb). How can I access a MySQL
    Luis> database from Python, without installing new modules? Does anyone
    Luis> have a few pieces of code that would achieve this?

The MySQL access in MySQLdb is actually done by the extension module _mysql,
which calls the client library provided by the MySQL folks.

Can't you install MySQLdb in your own directory tree, then add that to
sys.path at the top of your CGI script?  You should be able to install it
using something like

    python setup.py --prefix=/home/luis/local

then add

    import sys
    sys.path.insert(0, '/home/luis/local/lib/python1.5/site-packages')

to the very top of your CGI script.

BTW, at this point, a hosting company that only runs 1.5.2 on their servers
hoping to attract customers with that "carrot" doesn't rate a "sort of
supports Python" in my book.  They are running RH.  Is there a
/usr/bin/python2 executable?  If so, use this #! line:

    #!/usr/bin/python2

and use

    python2 setup.py --prefix=/home/luis/local

to install MySQLdb.

-- 
Skip Montanaro - skip at pobox.com
"Airplanes don't fly until the paperwork equals the weight of the
aircraft. Same with i18N." - from the "Perl, Unicode and i18N FAQ"




More information about the Python-list mailing list