Skip to content

Instantly share code, notes, and snippets.

@Drunkar
Last active August 29, 2015 14:09
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 Drunkar/1aaa6374c641a3e83d02 to your computer and use it in GitHub Desktop.
Save Drunkar/1aaa6374c641a3e83d02 to your computer and use it in GitHub Desktop.
import MySQLdb
connector = MySQLdb.connect(host="localhost", db="dbname", user="user", passwd="paswd", charset="utf8")
cursor = connector.cursor()
cursor.execute("select * from table limit 100")
result = cursor.fetchall()
if len(result) == 0:
print("no arecords. exit.")
cursor.close()
connector.close()
exit(0)
items = [item[0] for item in result]
for item in items:
print item
cursor.execute("INSERT INTO table (col1, col2, col3, created) VALUES (%s, %s, %s, NOW())",(val1, "val2", 0))
connector.commit()
cursor.close()
connector.close()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment