Skip to content

Instantly share code, notes, and snippets.

@swshan
Created September 22, 2015 06:22
Show Gist options
  • Save swshan/f42bf7dfe82cc3c317f7 to your computer and use it in GitHub Desktop.
Save swshan/f42bf7dfe82cc3c317f7 to your computer and use it in GitHub Desktop.
import MYSQLdb
db = MYSQLdb.connect(host="localhost", #host
user="john", # username
passwd="megajonhy", #password
db="jonhydb")
# you must create a Cursor object. It will let you execute all the queries you need
cur = db.cursor()
# Use all the SQL you like
cur.execute(SELECT * FROM YOUR_TABLE_NAME)
# print the first cell of all the rows
for row in cur.fetchall():
print row[0]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment