Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import MySQLdb
- import csv
- user = '' # your username
- passwd = '' # your password
- host = '' # your host
- db = '' # database where your table is stored
- table = '' # table you want to save
- con = MySQLdb.connect(user=user, passwd=passwd, host=host, db=db)
- cursor = con.cursor()
- query = "SELECT * FROM %s" % table
- cursor.execute(query)
- with open('outfile','w') as f:
- writer = csv.writer(f)
- for row in cursor.fetchall():
- writer.writerow(row)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement