PyMysql 错误:数据包序列号错误 - 预期为 1 为 0

Gur*_*niX 2 python mysql error-handling pymysql

我在 stackoverflow 和另一个编码示例网站中看到了该主题讨论的内容。但我找不到任何成熟的解决方案,有人修复这个错误吗?

错误信息:

ERROR:root:Can't connect to to MySQL server with error: (pymysql.err.InternalError) Packet sequence number wrong - got 1 expected 0
ERROR:root:Can't connect to to MySQL server with error: (pymysql.err.InternalError) Packet sequence number wrong - got 1 expected 0
ERROR:root:Can't connect to to MySQL server with error: (pymysql.err.InternalError) Packet sequence number wrong - got 1 expected 0
ERROR:root:Can't connect to to MySQL server with error: (pymysql.err.InternalError) Packet sequence number wrong - got 1 expected 0
ERROR:root:Can't connect to to MySQL server with error: (pymysql.err.InternalError) Packet sequence number wrong - got 1 expected 0
ERROR:root:Can't connect to to MySQL server with error: (pymysql.err.InternalError) Packet sequence number wrong - got 1 expected 0
Run Code Online (Sandbox Code Playgroud)

连接设置如下:

   "mysql+pymysql://{u}:{p}@{s}/{d}?charset=utf8".format(
                u=creds['username'],
                p=creds['password'],
                s=creds['host'],
                d=creds['dbname']
            ),
            pool_recycle=3500,
            echo=False,
            pool_pre_ping=True,
            pool_size=2,
            max_overflow=5
        )
Run Code Online (Sandbox Code Playgroud)

小智 5

通过此链接我得到:

在使用pymysql和python多线程时,通常我们会遇到以下问题:

它不能与所有子线程共享主线程创建的连接。这将导致以下错误: pymysql.err.InternalError: Packetequence number error - got 0 Expected 1 如果我们让每个子线程创建一个连接并在该子线程结束时关闭它,这是可行的,但显然会导致高与 MySQL 建立连接的成本。

他们似乎开发了其他库来解决这个问题:PyMySQL 连接池(相同的链接)