I do multiple requests to Mysqlsd and for specific users I get this error
MySQLdb._exceptions.OperationalError: (2013, ‘Lost connection to MySQL server during query’)
This error occurs on line
cursor.execute('Select * from process WHERE email=%s ORDER BY timestamp DESC LIMIT 20', ("<a href="https://getridbug.com/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="a3d7ccceceda909796c2e3ccd6d7cfccccc88dc0ccce">[email protected]</a>",))
But when I do the same query but for a different user, there is no problem.
cursor.execute('Select * from process WHERE email=%s ORDER BY timestamp DESC LIMIT 20', ("<a href="https://getridbug.com/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="a3c0c2c5c2cbdbdbdbdbe3c4cec2cacf8dc0ccce">[email protected]</a>",))
The page loads correctly.
More details on MySQL is given below
#modules used from flask_mysqldb import MySQL import MySQLdb.cursors #setup app.config['MYSQL_HOST'] = 'localhost' app.config['MYSQL_USER'] = 'myusername' app.config['MYSQL_PASSWORD'] = 'mypassword' app.config['MYSQL_DB'] = 'my_db' mysql = MySQL(app) #extract of requests made to db @app.route('/myhome', methods=['GET', 'POST']) def home_page(): email = "<a href="https://getridbug.com/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="92e6fdffffeba1a6a7f3d2fde7e6fefdfdf9bcf1fdff">[email protected]</a>" cursor = mysql.connection.cursor(MySQLdb.cursors.DictCursor) cursor.execute('SELECT * FROM mail WHERE email = %s', (email,)) completed = cursor.fetchone() cursor.execute('SELECT sum(transaction) FROM transactions WHERE email=%s', (email,)) points = cursor.fetchone() cursor.execute('Select * from process WHERE email=%s ORDER BY timestamp DESC LIMIT 20', (email,)) transactions = cursor.fetchall()
Also, this might be an issue of packet size but I haven’t had any issue till yesterday (there was more than 11 entries under the user tommy. I deleted 6 rows and it is still not working). Also if you think it is due to packet size, please tell me how can I solve it without increasing packet size because I am on a shared network and the hosting provider is not letting me increase the packet size limit.
Thank you for visiting the Q&A section on Magenaut. Please note that all the answers may not help you solve the issue immediately. So please treat them as advisements. If you found the post helpful (or not), leave a comment & I’ll get back to you as soon as possible.
There are multiple potential reasons for “server has gone away” and only one of them is due to data being too large for your max allowed packet size.
If it is caused by the data being too large, keep in mind that each row of result is its own packet. It’s not the whole result set that must fit in a packet. If you had 11 rows and you deleted 6 but still get the error, then the row that caused the problem still exists.
Remove the row that is too large. You might want to change the column data types of your table so that a given row cannot be too large. You showed a screenshot of some data, but I have no idea what data types you use. Hint: use
SHOW CREATE TABLE process.
max_allowed_packetas a session variable, since you don’t have access to change the global variable. Also keep in mind the client must also change its max allowed packet to match. Read https://dev.mysql.com/doc/refman/8.0/en/packet-too-large.html