我可以通过ssh连接到正确的MySQL/Mongodb数据库吗?

2024-10-03 04:28:00 发布

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

我正在尝试通过python中的ssh连接到正确的数据库,以便处理数据。你知道吗

这里有一个ssh如何在命令行中工作的例子。 http://ghtorrent.org/mysql.html

import pymysql
from sshtunnel import SSHTunnelForwarder

mypkey = paramiko.RSAKey.from_private_key_file("/Users/***/.ssh/id_rsa")
with SSHTunnelForwarder(
     ('web.ghtorrent.org', 3306), 
        ssh_username="ghtorrent",  
        ssh_pkey=mypkey, 
        ssh_private_key_password="*****",#my password for my pc
        remote_bind_address=('web.ghtorrent.org', 3306)) as server:  
    conn = pymysql.connect(host='127.0.0.1', 
                       port=server.local_bind_port,
                       user='ght', 
                       passwd='', 
                       db='ghtorrent')

根据我的代码,ssh无法连接到服务器。我不确定我的连接信息是否正确。你知道吗

因为它使用的是网站名称而不是IP地址,所以我不知道它是否有效。你知道吗

非常感谢!你知道吗


Tags: keyfromorgimportwebserverbindmy
1条回答
网友
1楼 · 发布于 2024-10-03 04:28:00

首先,GHTorrent SSH服务器正在监听端口22,您试图连接到3306,这是不正确的。你知道吗

另外,您是否尝试过直接指定SSH私钥路径? i、 e.ssh\u pkey=“/Users/***/.ssh/id\u rsa”

SSHTunnelForwarder(
 ('web.ghtorrent.org', 22), 
    ssh_username="ghtorrent",  
    ssh_pkey="/Users/***/.ssh/id_rsa", 
    ssh_private_key_password="*****",#my password for my pc
    remote_bind_address=('web.ghtorrent.org', 3306))

相关问题 更多 >