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.
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.
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:
https://docs.sqlalchemy.org/en/21/core/pooling.html
https://docs.sqlalchemy.org/en/21/core/connections.html#sqlalchemy.engine.Engine.dispose