文章详情

短信预约-IT技能 免费直播动态提醒

请输入下面的图形验证码

提交验证

短信预约提醒成功

MySQL----MySQL数据库出现Lost connection to MySQL server during query错误的解决办法

2023-08-31 18:40

关注

【原文链接】MySQL----MySQL数据库出现Lost connection to MySQL server during query错误的解决办法

Mysql数据库在查询数据库的时候回报出了如下异常:Lost connection to MySQL server during query,具体异常信息如下:

Traceback (most recent call last):  File "/opt/mugen/run_mugen.py", line 883, in run_testsuit    env = get_env(testsuit_name)  File "/opt/mugen/run_mugen.py", line 751, in get_env    row = session.query(Testsuit).filter(Testsuit.name == testsuit_name).first()  File "/usr/local/python3/lib/python3.9/site-packages/sqlalchemy/orm/query.py", line 2752, in first    return self.limit(1)._iter().first()  # type: ignore  File "/usr/local/python3/lib/python3.9/site-packages/sqlalchemy/orm/query.py", line 2855, in _iter    result: Union[ScalarResult[_T], Result[_T]] = self.session.execute(  File "/usr/local/python3/lib/python3.9/site-packages/sqlalchemy/orm/session.py", line 2229, in execute    return self._execute_internal(  File "/usr/local/python3/lib/python3.9/site-packages/sqlalchemy/orm/session.py", line 2114, in _execute_internal    conn = self._connection_for_bind(bind)  File "/usr/local/python3/lib/python3.9/site-packages/sqlalchemy/orm/session.py", line 1981, in _connection_for_bind    return trans._connection_for_bind(engine, execution_options)  File "", line 2, in _connection_for_bind  File "/usr/local/python3/lib/python3.9/site-packages/sqlalchemy/orm/state_changes.py", line 137, in _go    ret_value = fn(self, *arg, **kw)  File "/usr/local/python3/lib/python3.9/site-packages/sqlalchemy/orm/session.py", line 1108, in _connection_for_bind    conn = bind.connect()  File "/usr/local/python3/lib/python3.9/site-packages/sqlalchemy/engine/base.py", line 3251, in connect    return self._connection_cls(self)  File "/usr/local/python3/lib/python3.9/site-packages/sqlalchemy/engine/base.py", line 147, in __init__    Connection._handle_dbapi_exception_noconnection(  File "/usr/local/python3/lib/python3.9/site-packages/sqlalchemy/engine/base.py", line 2413, in _handle_dbapi_exception_noconnection    raise sqlalchemy_exception.with_traceback(exc_info[2]) from e  File "/usr/local/python3/lib/python3.9/site-packages/sqlalchemy/engine/base.py", line 145, in __init__    self._dbapi_connection = engine.raw_connection()  File "/usr/local/python3/lib/python3.9/site-packages/sqlalchemy/engine/base.py", line 3275, in raw_connection    return self.pool.connect()  File "/usr/local/python3/lib/python3.9/site-packages/sqlalchemy/pool/base.py", line 455, in connect    return _ConnectionFairy._checkout(self)  File "/usr/local/python3/lib/python3.9/site-packages/sqlalchemy/pool/base.py", line 1271, in _checkout    fairy = _ConnectionRecord.checkout(pool)  File "/usr/local/python3/lib/python3.9/site-packages/sqlalchemy/pool/base.py", line 725, in checkout    rec._checkin_failed(err, _fairy_was_created=False)  File "/usr/local/python3/lib/python3.9/site-packages/sqlalchemy/util/langhelpers.py", line 147, in __exit__    raise exc_value.with_traceback(exc_tb)  File "/usr/local/python3/lib/python3.9/site-packages/sqlalchemy/pool/base.py", line 722, in checkout    dbapi_connection = rec.get_connection()  File "/usr/local/python3/lib/python3.9/site-packages/sqlalchemy/pool/base.py", line 842, in get_connection    self.__connect()  File "/usr/local/python3/lib/python3.9/site-packages/sqlalchemy/pool/base.py", line 906, in __connect    pool.logger.debug("Error on connect(): %s", e)  File "/usr/local/python3/lib/python3.9/site-packages/sqlalchemy/util/langhelpers.py", line 147, in __exit__    raise exc_value.with_traceback(exc_tb)  File "/usr/local/python3/lib/python3.9/site-packages/sqlalchemy/pool/base.py", line 901, in __connect    self.dbapi_connection = connection = pool._invoke_creator(self)  File "/usr/local/python3/lib/python3.9/site-packages/sqlalchemy/engine/create.py", line 640, in connect    return dialect.connect(*cargs, **cparams)  File "/usr/local/python3/lib/python3.9/site-packages/sqlalchemy/engine/default.py", line 580, in connect    return self.loaded_dbapi.connect(*cargs, **cparams)  File "/usr/local/python3/lib/python3.9/site-packages/pymysql/connections.py", line 353, in __init__    self.connect()  File "/usr/local/python3/lib/python3.9/site-packages/pymysql/connections.py", line 633, in connect    self._request_authentication()  File "/usr/local/python3/lib/python3.9/site-packages/pymysql/connections.py", line 907, in _request_authentication    auth_packet = self._read_packet()  File "/usr/local/python3/lib/python3.9/site-packages/pymysql/connections.py", line 692, in _read_packet    packet_header = self._read_bytes(4)  File "/usr/local/python3/lib/python3.9/site-packages/pymysql/connections.py", line 748, in _read_bytes    raise err.OperationalError(sqlalchemy.exc.OperationalError: (pymysql.err.OperationalError) (2013, 'Lost connection to MySQL server during query')

在数据库中查看如下变量的值

可以看到这里的net_read_timeout和net_write_timeout分别为30和60秒,首先将这两个参数修改为更大一点的值。比如修改为300和900。如下所示,这里需要注意的是修改的时候需要分别设置global和session级别的,然后才会生效。

来源地址:https://blog.csdn.net/redrose2100/article/details/130909059

阅读原文内容投诉

免责声明:

① 本站未注明“稿件来源”的信息均来自网络整理。其文字、图片和音视频稿件的所属权归原作者所有。本站收集整理出于非商业性的教育和科研之目的,并不意味着本站赞同其观点或证实其内容的真实性。仅作为临时的测试数据,供内部测试之用。本站并未授权任何人以任何方式主动获取本站任何信息。

② 本站未注明“稿件来源”的临时测试数据将在测试完成后最终做删除处理。有问题或投稿请发送至: 邮箱/279061341@qq.com QQ/279061341

软考中级精品资料免费领

  • 历年真题答案解析
  • 备考技巧名师总结
  • 高频考点精准押题
  • 2024年上半年信息系统项目管理师第二批次真题及答案解析(完整版)

    难度     813人已做
    查看
  • 【考后总结】2024年5月26日信息系统项目管理师第2批次考情分析

    难度     354人已做
    查看
  • 【考后总结】2024年5月25日信息系统项目管理师第1批次考情分析

    难度     318人已做
    查看
  • 2024年上半年软考高项第一、二批次真题考点汇总(完整版)

    难度     435人已做
    查看
  • 2024年上半年系统架构设计师考试综合知识真题

    难度     224人已做
    查看

相关文章

发现更多好内容

猜你喜欢

AI推送时光机
位置:首页-资讯-数据库
咦!没有更多了?去看看其它编程学习网 内容吧
首页课程
资料下载
问答资讯