title: How to export Mysql Table data to excel file using python script?
body: <p>I have been trying to export that data from table to excel file using python 2.7.8 but I have not succeeded. Please help me. My Requirement is to export the data from the table and store it in local(windows C Drive).</p>
  
  <pre><code>#!/usr/bin/python
  import smtplib
  import base64
  import os
  import sys
  import xlswriter
  import xlwt
  import datetime
  import MySQLdb
  from pyh import *
  from email.MIMEMultipart import MIMEMultipart
  from email.MIMEText import MIMEText
  db = MySQLdb.connect("192.168.1.118","stp","stp","STP")
  cursor = db.cursor()
  query = ("""select * from stp_automation_output""")
  cursor.execute(query)
  myresults = cursor.fetchall()
  workbook = xlwt.Workbook()
  worksheet = workbook.add_sheet("My Sheet")
  #date_format = workbook.add_format({'num_format': 'd mmmm yyyy'})
  bold = workbook.add_format({'bold': 1})
  worksheet.write('A1','Sno',bold)
  worksheet.write('B1','function_name',bold)
  worksheet.write('C1','input1',bold)
  worksheet.write('D1','input2',bold)
  worksheet.write('E1','input3',bold)
  worksheet.write('F1','Expected_output',bold)
  worksheet.write('G1','Actual_output',bold)
  worksheet.write('H1','Result',bold)
  row = 1
  col = 0
  for Sno,function_name,input1,input2,input3,Expected_output,Actual_output,Result in (myresults):
    Sno = row[0]
    function_name = row[1]
    input1 = row[2]
    input2 = row[3]
    input3 = row[4]
    Expected_output = row[5]
    Actual_output = row[6]
    Result = row[7]
  workbook.save()
  </code></pre>