'Error 2013, 'Lost connection to MySQL server during query

I'm trying to connect to my mySQL server through a python script, using the pymysql library. I tried to see the other questions already asked, they led me to set: connect_timeout=31536000, max_allowed_packet=36777216 but I still get the same error, any idea how I can fix it?

Here's my code:

import pymysql
pymysql.connect(host="xxxx",
                       user="xxxx",
                       passwd="xxxx",
                       database="xxxx",
                       port=80,
                       connect_timeout=31536000,
                       max_allowed_packet=36777216)
cursor = connection.cursor()

Which return the error below:

OperationalError                          Traceback (most recent call last)
<ipython-input-19-467ba1c4e200> in <module>
----> 1 pymysql.connect(host="92.119.113.140",
      2                      user="signal_dblab",
      3                      passwd="eH5qQ8tB",
      4                      database="user30704231_dblab",
      5                      port=80,

~/anaconda3/envs/env1/lib/python3.8/site-packages/pymysql/connections.py in __init__(self, user, password, host, database, unix_socket, port, charset, sql_mode, read_default_file, conv, use_unicode, client_flag, cursorclass, init_command, connect_timeout, read_default_group, autocommit, local_infile, max_allowed_packet, defer_connect, auth_plugin_map, read_timeout, write_timeout, bind_address, binary_prefix, program_name, server_public_key, ssl, ssl_ca, ssl_cert, ssl_disabled, ssl_key, ssl_verify_cert, ssl_verify_identity, compress, named_pipe, passwd, db)
    351             self._sock = None
    352         else:
--> 353             self.connect()
    354 
    355     def __enter__(self):

~/anaconda3/envs/env1/lib/python3.8/site-packages/pymysql/connections.py in connect(self, sock)
    630             self._next_seq_id = 0
    631 
--> 632             self._get_server_information()
    633             self._request_authentication()
    634 

~/anaconda3/envs/env1/lib/python3.8/site-packages/pymysql/connections.py in _get_server_information(self)
   1053     def _get_server_information(self):
   1054         i = 0
-> 1055         packet = self._read_packet()
   1056         data = packet.get_all_data()
   1057 

~/anaconda3/envs/env1/lib/python3.8/site-packages/pymysql/connections.py in _read_packet(self, packet_type)
    690         buff = bytearray()
    691         while True:
--> 692             packet_header = self._read_bytes(4)
    693             # if DEBUG: dump_packet(packet_header)
    694 

~/anaconda3/envs/env1/lib/python3.8/site-packages/pymysql/connections.py in _read_bytes(self, num_bytes)
    746         if len(data) < num_bytes:
    747             self._force_close()
--> 748             raise err.OperationalError(
    749                 CR.CR_SERVER_LOST, "Lost connection to MySQL server during query"
    750             )

OperationalError: (2013, 'Lost connection to MySQL server during query')

These are the info of the db server:



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source