importmysql.connectorimporttimefrom mysql.connector importErrorfrom mysql.connector.connection importMySQLConnectionfrom mysql.connector importpoolingtry:
connection_pool= mysql.connector.pooling.MySQLConnectionPool(pool_name="pynative_pool",
pool_size=32,
pool_reset_session=True,
host='xh-dzu-mysql-mgrguangyoutest01',
port=5010,
database='sbtest',
user='sbtest',
password='temppass121')print ("Printing connection pool properties")print("Connection Pool Name -", connection_pool.pool_name)print("Connection Pool Size -", connection_pool.pool_size)#Get connection object from a pool
connection_object =connection_pool.get_connection()
time.sleep(3600)ifconnection_object.is_connected():
db_Info=connection_object.get_server_info()print("Connected to MySQL database using connection pool ... MySQL Server version on",db_Info)
cursor=connection_object.cursor()
cursor.execute("select database();")
record=cursor.fetchone()print ("Your connected to -", record)exceptError as e :print ("Error while connecting to MySQL using Connection pool", e)finally:#closing database connection.
if(connection_object.is_connected()):
cursor.close()
connection_object.close()print("MySQL connection is closed")