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