Lost connection to MySQL server during query, how can I fix this? Better fix this in my program.
import pymysql
connection = pymysql.connect(host='***',
user='***',
password='***',
db='***',
charset='utf8mb4',
cursorclass=pymysql.cursors.DictCursor
)
with connection.cursor() as cursor:
sql = "SELECT MAX(group_id) FROM topic_duplicate_check"
cursor.execute(sql) # Exception
r = cursor.fetchone()
max_gid = None
try:
max_gid = r['MAX(group_id)']
except:
pass
print(max_gid)
C:\ProgramData\Anaconda3\python.exe F:/group_topics/main.py Traceback (most recent call last): File "F:/group_topics/main.py", line 41, in cursor.execute(sql) File "C:\ProgramData\Anaconda3\lib\site-packages\pymysql\cursors.py", line 166, in execute result = self._query(query) File "C:\ProgramData\Anaconda3\lib\site-packages\pymysql\cursors.py", line 322, in _query conn.query(q) File "C:\ProgramData\Anaconda3\lib\site-packages\pymysql\connections.py", line 856, in query self._affected_rows = self._read_query_result(unbuffered=unbuffered) File "C:\ProgramData\Anaconda3\lib\site-packages\pymysql\connections.py", line 1057, in _read_query_result result.read() File "C:\ProgramData\Anaconda3\lib\site-packages\pymysql\connections.py", line 1340, in read first_packet = self.connection._read_packet() File "C:\ProgramData\Anaconda3\lib\site-packages\pymysql\connections.py", line 987, in _read_packet packet_header = self._read_bytes(4) File "C:\ProgramData\Anaconda3\lib\site-packages\pymysql\connections.py", line 1033, in _read_bytes CR.CR_SERVER_LOST, "Lost connection to MySQL server during query") pymysql.err.OperationalError: (2013, 'Lost connection to MySQL server during query')
Process finished with exit code 1