2017-03-20 6 views
0

파이썬 Pymysql을 사용하여 AWS RDS db에 연결합니다. 이것은 요즘 모두 작동했지만 지금은 DB에 연결할 수 없습니다. 나는 그것이 MySQL의 워크 벤치를 통해 연결 않습니다 동일한 시스템과 동일한 자격 증명을 사용하고 있지만, pycharm을 통해 문제가 해결되지 않습니다 그러나 ,Python mysql (pymysql 사용) 연결 실패

코드 :.

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) 

오류 :

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

이것이 생산 단계에서 발생하지 않도록하는 방법은 무엇입니까? (장래에 그러한 실패를 예방하십시오).

답변

-1

왜 이러한 연결 풀을 사용하지 않습니까?
연결 풀에서 자동 연결을 관리 할 수 ​​있으므로이 문제를 해결할 수 있습니다.

모든 파이썬 mysql 풀을 시도 할 수 있습니다.
풀 예제
this link 또는 직접 github 편리한 코드를 사용하십시오. PyMysqlPool