Python通过SSH隧道连接到MySQL服务器

2024-03-29 12:23:39 发布

您现在位置:Python中文网/ 问答频道 /正文

你好,我需要帮助远程连接到我的SQL数据库,该数据库托管在我的家庭服务器上。我可以使用terminal连接ok,但当我尝试使用pycharm时,会出现以下错误:

我收到一个“Unix域套接字不允许用于remoteaddress”错误。 我不确定应该为远程服务器和专用服务器以及最后一个主机设置哪些地址=ip。如果有人能帮我解释一下,那就太棒了,谢谢

这是我的密码: import mysql.connectorimport sshtunnel

with sshtunnel.SSHTunnelForwarder(('REMOTE_SERVERIP', 3306),ssh_username='darren',ssh_password='darren',remote_bind_address=('xxxxxxx'),local_bind_address=('0.0.0.0')) as tunnel:connection = mysql.connector.connect(user='darren',password='darren',host='xxxxxxx',database='SalesFindr',port=3306)


Tags: import服务器数据库sqlconnector远程bindaddress
1条回答
网友
1楼 · 发布于 2024-03-29 12:23:39

根据文档,远程绑定地址()必须是由IP地址和端口组成的元组

remote_bind_address (tuple): Remote tuple in the format (str, int) representing the IP and port of the remote side of the tunnel.

我们只能为本地绑定地址保留“Port”参数为空

local_bind_address (tuple): Local tuple in the format (str, int) representing the IP and port of the local side of the tunnel. Both elements in the tuple are optional so both ('', 8000) and ('10.0.0.1', ) are valid values

       Default: ``('0.0.0.0', RANDOM_PORT)``

因此,在您的代码中,尝试remote_bind_address=('xxxxxxx', 27018)(或任何替代27018的自由端口)

相关问题 更多 >