# sqlalchemy.exc.OperationalError: (pymysql.err.OperationalError) (2006, 'MySQL server has gone away')

- **ID:** `python/flask-sqlalchemy-operational-error-mysql-gone-away`
- **Domain:** python
- **Category:** network_error
- **Verification:** ai_generated
- **Fix Rate:** 80%

## Root Cause

Idle connections in the SQLAlchemy pool timed out server-side; pool_recycle not configured and pool_pre_ping off.

## Version Compatibility

| Version | Status | Introduced | Deprecated |
|---------|--------|------------|------------|
| 2.x | active | — | — |
| 3.x | active | — | — |

## Workarounds

1. **** (93% success)
   ```
   app.config['SQLALCHEMY_ENGINE_OPTIONS'] = {'pool_pre_ping': True, 'pool_recycle': 280}
   ```
2. **** (92% success)
   ```
   In create_engine: create_engine(url, pool_pre_ping=True, pool_recycle=280)
   ```

## Dead Ends

- **** — Only delays the problem; bad connections still get reused. (65% fail)
- **** — Disables pooling; performance collapses under load. (80% fail)
