python
network_error
ai_generated
true
sqlalchemy.exc.OperationalError: (pymysql.err.OperationalError) (2006, 'MySQL server has gone away')
ID: python/flask-sqlalchemy-operational-error-mysql-gone-away
80%Fix Rate
85%Confidence
0Evidence
2024-09-26First Seen
Version Compatibility
| Version | Status | Introduced | Deprecated | Notes |
|---|---|---|---|---|
| 2.x | active | — | — | — |
| 3.x | active | — | — | — |
Root Cause
Idle connections in the SQLAlchemy pool timed out server-side; pool_recycle not configured and pool_pre_ping off.
generic中文
SQLAlchemy 连接池中的空闲连接在服务端超时;未配置 pool_recycle 且 pool_pre_ping 关闭。
Workarounds
-
93% success
app.config['SQLALCHEMY_ENGINE_OPTIONS'] = {'pool_pre_ping': True, 'pool_recycle': 280} -
92% success
In create_engine: create_engine(url, pool_pre_ping=True, pool_recycle=280)
Dead Ends
Common approaches that don't work:
-
65% fail
Only delays the problem; bad connections still get reused.
-
80% fail
Disables pooling; performance collapses under load.