I have created a Telegram bot using Python & MySQL but I often get the Lost connection to MySQL server at 'localhost:3306', system error: 32 Broken pipe
error. I created the pool below but I still get the error.
host = "<some_host>"
database = "<some_database>"
user = "<some_user>"
password = "<some_password>"
poolname = "mysqlpool"
poolsize = 32
try:
connectionpool = mysql.connector.pooling.MySQLConnectionPool(pool_name = poolname, pool_reset_session = True, host = host, database = database, user = user, password = password)
connection = connectionpool.get_connection()
mycursor = connection.cursor()
for result in mycursor.stored_results():
print(result.fetchall())
except Error as e:
print("Error occured", e)
I have created a connection pool with MySQL database and I use the instance multiple times in the code. I use the instance to both read and write into the database. Whenever I needed the instance, I have just called the connection
variable and have run .commit()
or I just used mycursor.execute
to run a query. But after a while, I get the broken pipe error which seems to mean that there has been a connection timeout.
mysql.connector.errors.OperationalError: 2055: Lost connection to MySQL server at 'localhost:3306', system error: 32 Broken pipe
I have not used mycursor.close()
or connection.close()
anywhere in the code. How can I fix the error?