title: python mysql.connector Mysql Connection not available error
body: <p>I am using mysql.connector for interacting with mysql db. I create a db connection at the beginning of myscript and reuse the same connection for all database activity like select/insert/update etc. Randomly I get following exception,</p>
  
  <p>MySQL Connection not available.</p>
  
  <pre><code>Traceback (most recent call last):
    File "database.py", line 46, in query
      cursor = self.connection.cursor(buffered=True, dictionary=True)
    File "lib/python3.4/site-packages/mysql/connector/connection.py", line 807, in cursor
      raise errors.OperationalError("MySQL Connection not available.")
  mysql.connector.errors.OperationalError: MySQL Connection not available.
  2017-12-08 13:16:03,845 ERROR util.py 1247 MySQL Connection not available.
  </code></pre>
  
  <p>what could be the cause for above error?</p>
  
  <pre><code>    import mysql.connector
  
  
  class Database:
      """
          Simple Database class
      """
  
      def __init__(self, db_conf, logger):
          self.logger = logger
          try:
              self.connection = mysql.connector.connect(host=db_conf['host'], user=db_conf['user'], password=db_conf['password'],
                                                        database=db_conf['db'], port=db_conf['port'])
          except Exception as e:
              self.logger.exception(e)
              raise
  
      def insert_or_update(self, query, type):
          """
              Transactional query
          """
          try:
              cursor = self.connection.cursor(buffered=True)
              cursor.execute(query)
              self.connection.commit()
  
              if type == 'insert':
                  last_row_id = cursor.lastrowid
                  cursor.close()
                  return last_row_id
              elif type == 'update':
                  row_count = cursor.rowcount
                  cursor.close()
                  return row_count
          except Exception as e:
              self.connection.rollback()
              self.logger.info(query)
              self.logger.exception(e)
              raise
  
      def query(self, query):
          """
              Non transactional query
          """
          try:
              cursor = self.connection.cursor(buffered=True, dictionary=True)
              cursor.execute(query)
              self.connection.commit()
              result = cursor.fetchall()
              cursor.close()
              return result
          except Exception as e:
              self.logger.info(query)
              self.logger.exception(e)
              raise
  </code></pre>