Python sqlalchemy连接mysql8.0 出现Unknown system variable 'tx_isolation'

Unknown system variable 'tx_isolation’

  • 原因

Mysql8 has renamed tx_isolation to transaction_isolation,而包暂未更新。

  • 处理
  1. 把包升级为最新,重启项目,不行的话用方法2

  2. 手动改包

    • 找到你包的base.py文件,我的文件路径是:/<项目虚拟环境路径>/env/lib/python2.7/site-packages/sqlalchemy/dialects/mysql/base.py
    • 查找到tx_isolation,替换成transaction_isolation,如下:
    def get_isolation_level(self, connection):
        cursor = connection.cursor()
        # cursor.execute('SELECT @@tx_isolation')
        # tx_isolation 改为:transaction_isolation
        cursor.execute('SELECT @@transaction_isolation')
        val = cursor.fetchone()[0]
        cursor.close()
        if util.py3k and isinstance(val, bytes):
          val = val.decode()
          return val.upper().replace("-", " ")
    
  3. 重启项目,完毕!

你可能感兴趣的:(MySQL,错误处理)