我尝试使用Peewee和sshtunnel连接到远程mysql db:
with SSHTunnelForwarder(
('server.pt', 9922),
ssh_password="pass_ssh",
ssh_username="user_ssh",
remote_bind_address=('localhost', 3306)) as server:
myDB = pw.MySQLDatabase("dbname", user="db_user", passwd="db_pass")
但是我收到了错误
OperationalError: (2003, "Can't connect to MySQL server on 'localhost' ([Errno 111] Connection refused)")
你能帮帮我吗?
答案 0 :(得分:0)
您可能需要在server
对象中包含您已绑定隧道的本地端口:
myDb = pw.MySQLDatabase("dbname", host="localhost", port=server.local_bind_port, user="db_user", passwd="db_pass")
有关示例,请参阅here。