title: How to catch specific error “Lost connection to MySQL server during query”
body: <p>I am using </p>
  
  <pre><code>def mysql_handling(string):
      global cursor
      while True:
          try: 
              cursor.execute(string)
              if 'SELECT' not in string:
                  db.commit()
              break
          except MySQLdb.MySQLError:
              cursor.close()
                      print 'something went wrong!!'
              time.sleep(1)
              cursor = get_cursor()
  </code></pre>
  
  <p>To retry the query if the connection fails, but I <strong>ONLY</strong> want to retry the connection when I have the error <strong>“Lost connection to MySQL server during query”</strong>. (else the mysql_handling function gets in an infinite loop)</p>
  
  <p>So what should I use instead of <em>'except MySQLdb.MySQLError:'</em> ?</p>