0
votes

I am using Python Pymysql to connect to AWS RDS db. This was working all these days but now I am not able to connect to the db. However when I am using the same machine and same credentials it does connect through Mysql workbench, but through pycharm this does not work.,

Code :

   configParser = ConfigParser.RawConfigParser()
   configFilePath = r'docs/credentials.cfg'
   configParser.read(configFilePath)

   User = configParser.get('aws-config','user')
   Pswd = configParser.get('aws-config','pswd')
   Host = configParser.get('aws-config','hostdps')
   Databs = configParser.get('aws-config','databs')
   db = pymysql.connect(host=Host, user=User, password=Pswd, db=Databs, charset='utf8mb4', cursorclass=pymysql.cursors.DictCursor,local_infile=True)

Error :

  File "/usr/local/lib/python2.7/dist-packages/pymysql/__init__.py", line 90, in Connect
    return Connection(*args, **kwargs)
  File "/usr/local/lib/python2.7/dist-packages/pymysql/connections.py", line 688, in __init__
    self.connect()
  File "/usr/local/lib/python2.7/dist-packages/pymysql/connections.py", line 906, in connect
    self._request_authentication()
  File "/usr/local/lib/python2.7/dist-packages/pymysql/connections.py", line 1114, in _request_authentication
    auth_packet = self._read_packet()
  File "/usr/local/lib/python2.7/dist-packages/pymysql/connections.py", line 961, in _read_packet
    packet_header = self._read_bytes(4)
  File "/usr/local/lib/python2.7/dist-packages/pymysql/connections.py", line 995, in _read_bytes
    "Lost connection to MySQL server during query (%s)" % (e,))
pymysql.err.OperationalError: (2013, 'Lost connection to MySQL server during query ([Errno 104] Connection reset by peer)')

How to make sure that this does not happen on production? (prevent such failures in the future).

1

1 Answers

-1
votes

why u not use connection pool for these?
connection pool can auto manage connection,so can fix this.

U can try any python mysql pool .
pool example
for this this link or directly use github handy code .PyMysqlPool