SQLAlchemy error MySQL server has gone away

前端 未结 6 2096
清酒与你
清酒与你 2021-02-05 07:58

Error OperationalError: (OperationalError) (2006, \'MySQL server has gone away\') i\'m already received this error when i coded project on Flask, but i cant underst

6条回答
  •  遥遥无期
    2021-02-05 08:41

    https://docs.sqlalchemy.org/en/latest/core/pooling.html#disconnect-handling-optimistic

     def sql_read(cls, sql, connection):
        """sql for read action like select
        """
        LOG.debug(sql)
        try:
            result = connection.engine.execute(sql)
            header = result.keys()
            for row in result:
                yield dict(zip(header, row))
        except OperationalError as e:
            LOG.info("recreate pool duo to %s" % e)
            connection.engine.pool.recreate()
            result = connection.engine.execute(sql)
            header = result.keys()
            for row in result:
                yield dict(zip(header, row))
        except Exception as ee:
            LOG.error(ee)
            raise SqlExecuteError()
    

提交回复
热议问题