0
MySQL로 연결할 수 없습니다 사용 : 나는 mysql을 확인 하였다 연결 속편 Pro를 사용 파이썬은 sshtunnel 내가 터널 내 연결에 <code>python2.7</code>에 <code>sshtunnel</code> 및 <code>MySQLdb</code>를 사용하려고하고 다음과 같은 문제에 직면하고있어
을하지만, 파이썬 코드를 작동하지 않았다!및 코드는 다음과 같다 :
속편 Pro는 다음과 같이이다
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)
내가 알고 싶어 내가 좋아하는 몇 가지 예제 코드를 검색
`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)
그게 내가 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 "<stdin>", line 6, in <module>
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
도움 주셔서 감사합니다. 하지만 여전히 작동하지 않습니다. – chilun
어떤 오류가 있습니까? 메시지? –
기사에 오류 메시지를 추가했습니다. 감사합니다. – chilun