The MySQL Connection Pool operates on the client side to ensure that a MySQL client does not constantly connect to and disconnect from the MySQL server. It is designed to cache idle connections in the MySQL client for use by other users as they are needed.
Using connection pools helps to both alleviate connection management overhead and decrease development tasks for data access. Each time an application attempts to access a backend store (such as a database), it requires resources to create, maintain, and release a connection to that datastore.
In my code I am opening two mysql connections and using HTTP requests to insert data into database
g.db = mysql.connector.connect(user=a ,password=password, host=localhost,database=mysq1)
g.db1 = mysql.connector.connect(user=b,password=password, host=localhost,database=mysql2)
@app.route('/user/<db>')
def insert(db):
#code for inserting data into mysql1 database
#code for inserting data into mysql2 database
I am making HTTP requests to select the databases.
curl -i 'localhost:5000/user/mysql1' #
It is working well, data is getting inserted into the selected database. But I was thinking of creating a connection pool for the two connections and then used that pool.
Questions:
How to implement the mysql connection pooling?
Is there other better way of initializing connections.Currently connection get opened at each request.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With