Oracle released a pure-python mysql connector with connection pooling support.
Create a connection pool is really easy. You can try the following snippets in ipython
import mysql.connector auth = { "database": "test", "user": "user", "password": "secret" } # the first call instantiates the pool mypool = mysql.connector.connect( pool_name = "mypool", pool_size = 3, **auth)
All the subsequent calls to connect(pool_name=”mypool”) will be managed by the pool
# this won't create another connection # but lend one from the pool conn = mysql.connector.connect( pool_name = "mypool", pool_size = 3, **auth) # now get a cursor and play c = conn.cursor() c.execute("show databases") c.close()
Closing the connection will just release the connection to the pool: we’re not closing the socket!
conn.close()