python ssh mysql_python使用sshtunnel无法连接到mysql

我正在尝试使用sshtunnel中的MySQLdb和python2.7来隧道连接并面临以下问题:

我用Sequel Pro连接mysql没关系,但是python代码没有用!

Sequel Pro是这样的:

和代码是这样的:

`from sshtunnel import SSHTunnelForwarder

import MySQLdb

with SSHTunnelForwarder(

('2.2.2.2', 22),

ssh_username='name2',

ssh_password='mypassword',

remote_bind_address=('127.0.0.1', 3306)

) as tunnel:

connection = MySQLdb.connect(

user='name1',

password='mypassword',

host='1.1.1.1',

database='mydata',

port=3306)

我搜索了一些示例代码:

from sshtunnel import SSHTunnelForwarder

import MySQLdb

with SSHTunnelForwarder(

(_host, _ssh_port),

ssh_username=_username,

ssh_password=_password,

remote_bind_address=(_remote_bind_address, _remote_mysql_port),

local_bind_address=(_local_bind_address, _local_mysql_port)

) as tunnel:

connection = MySQLdb.connect(

user=_db_user,

password=_db_password,

host=_local_bind_address,

database=_db_name,

port=_local_mysql_port)

我想知道我是否以正确的方式构建ssh或连接到mysql?感谢帮助!

更新

错误信息:

2017-06-15 17:52:58,415| ERROR | Could not connect to gateway 1.1.1.1:22 : 110

Traceback (most recent call last):

File "", line 6, in

File "build/bdist.linux-x86_64/egg/sshtunnel.py", line 1483, in __enter__

File "build/bdist.linux-x86_64/egg/sshtunnel.py", line 1225, in start

File "build/bdist.linux-x86_64/egg/sshtunnel.py", line 1037, in _raise

sshtunnel.BaseSSHTunnelForwarderError: Could not establish session to SSH gateway

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值