Developer Resources’s Weblog

June 13, 2008

Python mysql access

Filed under: mysql, Python — Tags: , , , — developerresources @ 11:55 pm

Here is how you can access mysql using python:

#!/usr/bin/python

import MySQLdb
import sys
import time

db = MySQLdb.connect(host="reportsdb",user="root", db="tool_metrics")
dbc = db.cursor()
str = "select '1','2','3'";
dbc.execute(str)
records = dbc.fetchall()

for r in records:
    print r[0]+","+r[1]+","+r[2]

For more information on Python and databases I recommend the following book for futher reading: <a href=”http://www.amazon.com/gp/product/0596009402?ie=UTF8&tag=develoresour-20&linkCode=as2&camp=1789&creative=9325&creativeASIN=0596009402″>Python Pocket Reference (Pocket Reference (O’Reilly))</a><img src=”http://www.assoc-amazon.com/e/ir?t=develoresour-20&l=as2&o=1&a=0596009402″ width=”1″ height=”1″ border=”0″ alt=”" style=”border:none !important; margin:0px !important;” />

Advertisement

Leave a Comment »

No comments yet.

RSS feed for comments on this post. TrackBack URI

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Connecting to %s

Theme: Silver is the New Black. Blog at WordPress.com.

Follow

Get every new post delivered to your Inbox.