The reason for this error is to connect to MySQL through pymysql, and there is no operation to close the connection, so there will be no problems in a short time, and the connection will be confused if the connection is maintained for a long time. Although looking at my code is correct, I still report
pymysql.err.InterfaceError: (0,”) error. So this connection is either connected and then closed when it is used up. Or just use the following code to check if the connection exists, and reconnect if disconnected.
db = pymysql.connect(host = ' 127.0.0.1 ' ,port=3306,user = ' user ' , passwd = ' pwd ' , db = ' db_name ' , charset = ' utf8 ' ) sql ='select * from table_name' db.ping(reconnect = True) cur.execute(sql) db.commit()
end!