Sunday, January 1, 2012

MySQL Connect in Python

#!/usr/bin/env python
import pymysql

conn = pymysql.connect(host='localhost', user='root', passwd='cyrushellborg666', db='brewing')
cur = conn.cursor()
cur.execute("SHOW TABLES")
# print cur.description
# r = cur.fetchall()
# print r
# ...or...
for r in cur:
   print r
cur.close()
conn.close()

No comments: