Skip to content

Instantly share code, notes, and snippets.

@davepape
Created April 2, 2014 15:30
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save davepape/9936463 to your computer and use it in GitHub Desktop.
Save davepape/9936463 to your computer and use it in GitHub Desktop.
# Query the example "world" database using MySQLdb
import MySQLdb
db = MySQLdb.connect(host='localhost', port=3306, user='myusername', passwd='mypassword', db='world')
cur = db.cursor()
cur.execute("SELECT ID, Name, Population from City order by Name limit 3")
for row in cur.fetchall():
print "ID:",row[0], "Name:", row[1], "Pop:", row[2]
cur.close()
db.close()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment