Sometimes, we want to fix lost connection to MySQL server during query with Python.
In this article, we’ll look at how to fix lost connection to MySQL server during query with Python.
How to fix lost connection to MySQL server during query with Python?
To fix lost connection to MySQL server during query with Python, we increase the max_allowed_packet size.
To do this, we write
connection.execute('set max_allowed_packet=67108864')
to call connection.execute with a string to set the max_allowed_packet to a bigger size.
Then in /etc/mysql/my.cnf we add max_allowed_packet=64M to set the max packet size to 64MB.
Conclusion
To fix lost connection to MySQL server during query with Python, we increase the max_allowed_packet size.