Last active
January 3, 2016 07:09
-
-
Save basilleaf/8427258 to your computer and use it in GitHub Desktop.
Connect to MySQL from Python
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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