Advertisement
Guest User

Untitled

a guest
Mar 4th, 2015
190
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.45 KB | None | 0 0
  1. import MySQLdb
  2. import csv
  3.  
  4. user = '' # your username
  5. passwd = '' # your password
  6. host = '' # your host
  7. db = '' # database where your table is stored
  8. table = '' # table you want to save
  9.  
  10. con = MySQLdb.connect(user=user, passwd=passwd, host=host, db=db)
  11. cursor = con.cursor()
  12.  
  13. query = "SELECT * FROM %s" % table
  14. cursor.execute(query)
  15.  
  16. with open('outfile','w') as f:
  17. writer = csv.writer(f)
  18. for row in cursor.fetchall():
  19. writer.writerow(row)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement