How to solve the connection problem pyMySQL?

import pymysql
class Users:
 def __init__(self):
 self.conn = pymysql.connect('localhost', 'admin', 'pass', 'myDB')
 self.cursor = self.conn.cursor()
 def insert(self, user_id, username):
 with self.conn:
 self.cursor.execute('INSERT INTO users(user_id, username) '
 'VALUES (%s,%s)', (user_id, username))
 self.conn.commit()


Connect module pyMySQL in Python script the first time, about 1-2 minutes the script normally accesses the database. Then hangs and displays the following error:
CR.CR_SERVER_LOST, "Lost connection to MySQL server during query")
pymysql.err.OperationalError: (2013, 'Lost connection to MySQL server during query')

What could be wrong?
April 19th 20 at 12:11
1 answer
April 19th 20 at 12:13
Solution
Thank you, the problem was the wait_timeout=10, increased to 8 hours. - Taurean75 commented on April 19th 20 at 12:16

Find more questions by tags PythonMySQL