0
我正在使用Python Pymysql連接到AWS RDS 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)')
如何確保這不會發生在生產上? (防止將來出現這種故障)。