2
我正在使用Python 3.4(帶有Pycharm)的Windows 7,並嘗試通過SSH使用私鑰來訪問遠程mySQL數據庫。如何使用Python 3.5通過SSH隧道連接到MySQL數據庫?
我用SSHTunnel(ghithub_link)來設置SSHTunnel如下:
from sshtunnel import SSHTunnelForwarder
server = SSHTunnelForwarder(
("blablabla.ddns.net", 3307),
ssh_host_key=None,
ssh_username="name",
ssh_password=None,
ssh_private_key="E:\id_rsa",
ssh_private_key_password="pssrd",
remote_bind_address=('192.168.0.24', 3306))
的我連接到MySQL數據庫使用Oracle的MySQL的連接器的Python(source)如下:
cnx=mysql.connector.connect(user='user_worker', password='passwrd',host="blablabla.ddns.net", port=3307, database='base_101')
cnx.close()
我收到以下錯誤:
Traceback (most recent call last):
File "C:/Users/PycharmProjects/untitled _Get.py", line 37, in <module> cnx=mysql.connector.connect(user='user_worker', password=’pass',host="blablabla.ddns.net", port=22, database=’base_101')
File "C:\Users \Python34\site-packages\mysql\connector\__init__.py", line 179, in connectreturn MySQLConnection(*args, **kwargs)
File "C:\Users \Python34\site-packages\mysql\connector\connection.py", line 95, in __init__self.connect(**kwargs)
File "C:\Users \Python34\site-packages\mysql\connector\abstracts.py", line 719, in connectself._open_connection()
File "C:\Users\YOANN\AppData\Roaming\Python\Python34\site-packages\mysq\connector\connection.py", line 206, in _open_connectionnself._socket.open_connection()
File "C:\Users\YOANN\AppData\Roaming\Python\Python34\site-packages\mysq\connector\network.py", line 475, in open_connection errno=2003, values=(self.get_address(), _strioerror(err)))
mysql.connector.errors.InterfaceError: 2003: Can't connect to MySQL server on '127.0.0.1:3306' (10061 Aucune connexion n’a pu être établie car l’ordinateur cible l’a expressément refusée)
我假設問題來自港口,但我無法弄清楚。在一個另一方面我可以連接到通過SSH和使用pycharm數據庫工具SSH-關鍵,所以在服務器側,也不是關鍵/ ssh連接沒問題)的基礎。
以下是使用Oracle-Worbench成功完成工作的方式。這就是我想在Python做:工作臺,例如-image.img(http://goo.gl/xU8iue) 。 – ylnor