r/pythonhelp • • Sep 30 '26

Closing mysql-connector-python pooled sockets

/r/Python/comments/1wuflfo/closing_mysqlconnectorpython_pooled_sockets/
1 Upvotes

2 comments sorted by

View all comments

1

u/latkde Sep 30 '26

There's no documented way to do this. In practice there's a private/undocumented _remove_connections() method, but this shouldn't be used.

The practical solution is to use a different pool implementation. I strongly recommend using SQLAlchemy, which has a mature connection pooling system, and a documented way to close pools (Engine.dispose()). SQLAlchemy also allows you to use more mature MySQL client libraries, instead of the effectively-unmaintained mysql-connector-python.

Relevant docs:

1

u/RomfordNavy Sep 30 '26

What more mature MySQL client libraries are used in SQLAlchemy? If there are better connection pooling connection libraries available I would happily move to using them but don't want the whole SQLAlchemy overhead and additional associated complication.