Skip to content

Instantly share code, notes, and snippets.

@mryoshio
Created April 4, 2012 09:41
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 mryoshio/2300017 to your computer and use it in GitHub Desktop.
Save mryoshio/2300017 to your computer and use it in GitHub Desktop.
Update many records all at once using pymysql module.
def main():
"""
Execute three actions.
1. get id, new title from a file. e.g. [(title, id),(title, id)]
2. update DB
"""
id_titles = get_id_titles(EXPECTED_LIST)
conn = pymysql.Connect(host=DB_HOST, db=DB, user=DB_USER, passwd=DB_PSWD, charset=CHARSET)
cursor = conn.cursor()
query = "UPDATE aegifpage SET page_title = %s where page_id = %s"
cursor.executemany(query, id_titles)
cursor.close()
conn.commit()
conn.close()
print "updated successfully"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment