A
A
AlmazKayum2020-04-15 20:12:19
MySQL
AlmazKayum, 2020-04-15 20:12:19

How to solve pyMySQL connection problem?

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()


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

What can be wrong?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
S
Sergey Gornostaev, 2020-04-15
@AlmazKayum

Reason . Solution .

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question