Skip to content

Instantly share code, notes, and snippets.

@utsavsabharwal
Created August 17, 2012 05:28
Show Gist options
  • Select an option

  • Save utsavsabharwal/3376193 to your computer and use it in GitHub Desktop.

Select an option

Save utsavsabharwal/3376193 to your computer and use it in GitHub Desktop.
MySQL Python API Example
from datetime import datetime
import hashlib
import MySQLdb
conn = MySQLdb.connect (host = "localhost", user = "root", db = "spider")
cursor = conn.cursor ()
#INSERTION/UPDATE Statements
sql="insert ignore into url_queue select * from something"
cursor.execute(sql)
conn.commit()
#SELECTION Statements
sql="select * from url_queue LIMIT 10"
cursor.execute(sql)
rows = cursor.fetchall() #each row is a tuple while each coloumn of that row is also a tuple ((a,b,c), (d,e,f))
for row in rows:
print list(row)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment