Skip to content

Instantly share code, notes, and snippets.

@alexsoft
Created January 4, 2013 15:43
Show Gist options
  • Save alexsoft/4453570 to your computer and use it in GitHub Desktop.
Save alexsoft/4453570 to your computer and use it in GitHub Desktop.
Python: MySQLdb
import MySQLdb
db = MySQLdb.connect(host="localhost",\
user="USERNAME",\
passwd="PASSWORD",\
db="DB_NAME",\
charset="utf8")
cursor = db.cursor()
sql = "SELECT a,b FROM sometable"
cursor.execute(sql)
data = cursor.fetchall()
for record in data:
a, b = record
print a, b
db.close()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment