I initialized the connection globally and I'm trying to reuse the same connection every time while inserting(bulk). The insert statement looks like this.
start transaction; INSERT INTO test VALUES (1,2,3),(2,3,4),(3,4,5); commit;
The code will look like this.
def test():
mysql_conn = mysql.connect(host=server['host'], user=server['user'], password=server['passwd'])
while True:
## code to get bulk insert statement
## example insert statement.
insert_statement = 'start transaction; INSERT INTO test VALUES (1,2,3),(2,3,4),(3,4,5); commit;'
mysql_conn.execute(insert_statement)
For the first two loops, it executed as expected after that it started raising an exception
mysql.connector.errors.OperationalError: MySQL Connection not available.
I don't have any idea why the connection is expiring here. Even though I had increased the connection timeout also still got the same error