# sqlalchemy.exc.OperationalError: (pymysql.err.OperationalError) (2013, 'Lost connection to MySQL server during query')

- **ID:** `python/mysql-connection-reset`
- **Domain:** python
- **Category:** network_error
- **Verification:** ai_generated
- **Fix Rate:** 80%

## Root Cause

MySQL 服务器关闭了连接，可能是由于超时、服务器重启或网络问题。

## Version Compatibility

| Version | Status | Introduced | Deprecated |
|---------|--------|------------|------------|
| 1.4.x | active | — | — |
| 2.0.x | active | — | — |

## Workarounds

1. **** (90% success)
   ```
   使用 SQLAlchemy 的 pool_pre_ping=True 参数，自动检测并重建死连接。
   ```
2. **** (85% success)
   ```
   设置连接池回收时间：pool_recycle=3600
   ```

## Dead Ends

- **** — 增加 MySQL 的 wait_timeout，但需要重启服务器且影响所有连接。 (40% fail)
- **** — 在应用层无限重试，但可能造成资源浪费和死循环。 (60% fail)
