Mysql in Python?

Jeremy Jones zanesdad at bellsouth.net
Thu Aug 26 14:05:58 EDT 2004


Stefan Stolz wrote:

>Hello,
>i tried to find something about mysql in www.python.org, but found
>nothing...
>What can you recommend to use for getting and putting data from and into a
>mysql database?
>On my Suse 9.1 i found a rpm python-mysql. In the web i found the hk_classes
>from www.knoda.org. This should do also such things.
>Can you recommend something? What do you use?
>Thank you very much for the info.
>  
>
I have used a MySQLdb module before.  Here's a piece of code that I 
found lying around my home directory:

import MySQLdb

if __name__ == "__main__":
    db_conn = 
MySQLdb.connect(host='hostname',db='database_name',user='username',passwd='password')
    handle = db_conn.cursor()
    query = "SELECT * FROM foo"
    handle.execute(query)
    Results = handle.fetchall()
    print Results

I'm not sure, but I believe that MySQLdb is included in this project:

http://sourceforge.net/projects/mysql-python

(which appears to have been updated only a couple of months back, so 
that's good news).



More information about the Python-list mailing list