vishal
vishal

Reputation: 104

Mysql connector - How to use connection pool with multiple databases?

I have more than 30 databases and I want to use connection pool in my python code.

conn = mysql.connector.connect(
        host=MYSQL_HOST,
        user=MYSQL_USERNAME,
        passwd=MYSQL_PASSWORD,
        database=database,
        charset='utf8',
        use_unicode=True,
        pool_name='connection_pool',
        pool_size=10
)

In API calls, based on sub-domain, I have to decide which database to connect. For example "abc.mydomain.com", so I have to connect to abc's database. It is working fine with a single connection but It's taking time each time it tries to connect to the database.

Upvotes: 1

Views: 906

Answers (1)

Sai Vamshi
Sai Vamshi

Reputation: 1

Old thread but, you want a connection pool for 30 databases, since it is taking time to break and establish a new connection, it is better to establish 30 different connection pools for 30 connections and store them in dictionary based on database name, and from my research a connection pool can only store a single database connection and even if we try add multiple db connections to it, when we try to access one of them, there is a half half chance of getting either one, so it is more efficient to use multiple connection pools.

Upvotes: 0

Related Questions