title: Delete older data from MySQL database using Python
body: <p>I want to delete records older than 7 days automatically, but it doesn't work. Message is showing that older data is deleted, but actually it did not delete the data. </p>
  
  <p>My code is:</p>
  
  <pre><code>try:
      db= MySQLdb.connect("localhost","root","","testDB")
      cursor=db.cursor()
      sql="DELETE FROM CALLRECORD WHERE DATE&lt; DATE_SUB(NOW(), INTERVAL 7 DAY)"
      try:
          cursor.execute(sql)
          db.commit()
          print "Deleted Older Data from database"
  
      except:
          db.rollback()
          print "Cann't delete older data"
      db.close()
  
  except:
      print "localserver not connected"
  </code></pre>