Forked from utsavsabharwal/mysql-python-api-example.py
Last active
June 6, 2016 01:21
-
-
Save camark/f7643e5f2efaa1b6bb6fc0c6901ce0be to your computer and use it in GitHub Desktop.
MySQL Python API Example
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
| from datetime import datetime | |
| import hashlib | |
| import MySQLdb | |
| conn = MySQLdb.connect (host = "localhost", user = "root", passwd = '',db = "spider",charset = 'utf8') | |
| 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