【发布时间】:2018-04-14 15:42:16
【问题描述】:
这可能是尝试使用 python 在远程机器上运行 mysql 查询的重复问题。 我为此使用 pymysql 和 SSHTunnelForwarder。
mysqldb 位于不同的服务器上(192.168.10.13 和端口 5555)。
我正在尝试使用以下 sn-p:
with SSHTunnelForwarder(
(host, ssh_port),
ssh_username = ssh_user,
ssh_password = ssh_pass,
remote_bind_address=('127.0.0.1', 5555)) as server:
with pymysql.connect("192.168.10.13", user, password, port=server.local_bind_port) as connection:
cursor = connection.cursor()
output = cursor.execute("select * from billing_cdr limit 1")
print output
这是正确的做法吗?
我看到以下错误:
sshtunnel.BaseSSHTunnelForwarderError: Could not establish session to SSH gateway
还有其他推荐的库吗?
【问题讨论】:
标签: python python-2.7 pymysql