Categories
Python Answers

How to fix lost connection to MySQL server during query with Python?

Spread the love

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.

By John Au-Yeung

Web developer specializing in React, Vue, and front end development.

Leave a Reply

Your email address will not be published. Required fields are marked *