Skip to content

Instantly share code, notes, and snippets.

@basilleaf
Last active January 3, 2016 07:09
Show Gist options
  • Select an option

  • Save basilleaf/8427258 to your computer and use it in GitHub Desktop.

Select an option

Save basilleaf/8427258 to your computer and use it in GitHub Desktop.
Connect to MySQL from Python
import MySQLdb
# using 127.0.0.1 here rather than 'localhost' solves a socket error
db = MySQLdb.connect(host="127.0.0.1", user="foo", passwd="bar", db="qoz")
cursor = db.cursor()
q = "MY QUERY"
cursor.execute(q)
data = cursor.fetchall()
for row in data :
# do stuff
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment