测试开发技术网站
博客
设计
设计
开发
Python
测试
unittest
运维
Linux基础应用
CI/CD
CI/CD
数据库
数据库
云计算
云计算
云原生
云原生
爬虫
爬虫
数据分析
数据分析
人工智能
人工智能
登录
注册
MySQL----MySQL数据库出现Lost connection to MySQL server during query错误的解决办法
收藏本文
作者:redrose2100 类别: 日期:2023-05-28 07:52:12 阅读:956 次 消耗积分:0 分
[【原文链接】MySQL----MySQL数据库出现Lost connection to MySQL server during query错误的解决办法](http://devops-dev.com/article/631) # 问题描述 Mysql数据库在查询数据库的时候回报出了如下异常:Lost connection to MySQL server during query,具体异常信息如下: ```bash 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') ``` # 解决办法: 1、在数据库中查看如下变量的值 ![](https://redrose2100.oss-cn-hangzhou.aliyuncs.com/img/15079f24-fce8-11ed-8e5c-0242ac110004.png) 可以看到这里的net_read_timeout和net_write_timeout分别为30和60秒,首先将这两个参数修改为更大一点的值。比如修改为300和900。如下所示,这里需要注意的是修改的时候需要分别设置global和session级别的,然后才会生效。 ![](https://redrose2100.oss-cn-hangzhou.aliyuncs.com/img/bc8a2f96-fce8-11ed-8e5c-0242ac110004.png)
始终坚持开源开放共享精神,同时感谢您的充电鼓励和支持!
版权所有,转载本站文章请注明出处:redrose2100, http://blog.redrose2100.com/article/631
上一篇:
展板海报、文化墙设计
下一篇:
Python----Python中使用logging模块打印异常调用栈的三种方法
搜索
个人成就
出版书籍
《Pytest企业级应用实战》
测试开发技术全栈公众号
测试开发技术全栈公众号
DevOps技术交流微信群
加微信邀请进群
常用网站链接
开源软件洞察
云原生技术栈全景图
Python语言官方文档
Golang官方文档
Docker官方文档
Jenkins中文用户手册
Scrapy官方文档
VUE官方文档
Harbor官方文档
openQA官方文档
云原生开源社区
开源中国
Kubernetes中文文档
Markdown语法官方教程
Kubernetes中文社区
Kubersphere官方文档
BootStrap中文网站
JavaScript中文网
NumPy官方文档
Pandas官方文档
GitLink确实开源网站
数据库排名网站
编程语言排名网站
SEO综合查询网站
数学加减法练习自动生成网站
Kickstart Generator
文章分类
最新文章
最多阅读
特别推荐
×
Close
登录
注册
找回密码
登录邮箱:
登录密码:
图片验证码:
注册邮箱:
注册密码:
邮箱验证码:
发送邮件
注册邮箱:
新的密码:
邮箱验证码:
发送邮件