我正在尝试连接到Mysql Azure服务器,却收到错误消息:
(2013, 'Lost connection to MySQL server during query')
在connect命令上。
我在这里阅读了几个类似的问题:
Error 2013 - Lost Connection to MySQL server during query
Error 2013 - Lost Connection to MySQL server during query
pymysql,Lost connection to MySQL server during query
但是根据追溯,我的错误发生在connect()
上,上面的问题与对数据库的大查询更相关。
这是回溯:
File "updateStock.py", line 125, in <module>
main()
File "updateStock.py", line 65, in main
db = connection.connect()
File "updateStock.py", line 22, in connect
db="mydb")
File "/usr/local/lib/python2.7/dist-packages/pymysql/__init__.py", line 94, in Connect
return Connection(*args, **kwargs)
File "/usr/local/lib/python2.7/dist-packages/pymysql/connections.py", line 327, in __init__
self.connect()
File "/usr/local/lib/python2.7/dist-packages/pymysql/connections.py", line 598, in connect
self._request_authentication()
File "/usr/local/lib/python2.7/dist-packages/pymysql/connections.py", line 852, in _request_authentication
auth_packet = self._read_packet()
File "/usr/local/lib/python2.7/dist-packages/pymysql/connections.py", line 656, in _read_packet
packet_header = self._read_bytes(4)
File "/usr/local/lib/python2.7/dist-packages/pymysql/connections.py", line 702, in _read_bytes
CR.CR_SERVER_LOST, "Lost connection to MySQL server during query")
pymysql.err.OperationalError: (2013, 'Lost connection to MySQL server during query')
这是我的连接代码:
class DB:
conn = None
def connect(self):
self.conn = pymysql.connect(host="myserver.database.azure.com",
user="usert@myserver.mysql.database.azure.com",
passwd="****",
port=3306,
db="mydb")
return self
def get_cursor(self):
return self.conn.cursor(buffered=True)
def main():
# try:
connection = DB()
db = connection.connect()
cursor = db.get_cursor()
有人可以帮助我发现问题吗?