我在工作中使用python连接到path sql。在python中,我使用以下命令:
from sshtunnel import SSHTunnelForwarder
import pandas as pd
import psycopg2
tunnel = SSHTunnelForwarder(
('name', 22)
, ssh_private_key="path_to_ssh"
, ssh_username="username"
, remote_bind_address=('path', 5432)
, local_bind_address = ('XXX.X.X.X', 5431)
)
tunnel.start()
con_data = psycopg2.connect(host = 'XXX.X.X.X'
, database = "name"
, user = "user"
, password = "passwd"
, port = 5431
, sslmode ='require')
def create_df(query, con):
cur = con.cursor()
cur.execute(query)
df = cur.fetchall()
colnames = [desc[0] for desc in cur.description]
cur.close()
df = pd.DataFrame(df, columns=colnames)
return df
query = '''SELECT * FROM table'''
create_df(query, con_data)
在r语言中,我没有找到任何方法来创建像上面这样的连接!!!你有没有试过这个?请提供一个r包来启动ssh并从sql创建查询连接
暂无答案!
目前还没有任何答案,快来回答吧!