抽取数据库文件:
def exportmysql(request):
conn= MySQLdb.connect(
host='192.168.137.3',
port = 3306,
user='root',
passwd='1234567',
db ='DEVOPS',
charset='UTF8'
)
cur = conn.cursor()
a = cur.execute("select ip,info,env from machine_info")
info = cur.fetchall()
response = HttpResponse(content_type='text/csv')
response['Content-Disposition'] = 'attachment; filename="somefilename.csv"'
writer = csv.writer(response)
for row in info:
writer.writerow(row)
return response